Last active
March 11, 2019 00:21
-
-
Save felipecarvalho/1d41821144a1645428ff4a3000d5d74a to your computer and use it in GitHub Desktop.
Snippet to check brazilian license plate from vehicles in Dart language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Created by Felipe Carvalho [http://github.com/felipecarvalho] | |
| // You can play with this code on DartPad [https://dartpad.dartlang.org/1d41821144a1645428ff4a3000d5d74a] | |
| void main() { | |
| String _regOldPlate = r"^[a-zA-Z]{3}[-][0-9]{4}$"; | |
| String _regNewPlate = r"^[a-zA-Z]{3}[0-9]{1}[a-zA-Z]{1}[0-9]{2}$"; | |
| RegExp _currentPlate; | |
| void checkNewPlate(bool _value, String _plate) { | |
| _currentPlate = RegExp(_value ? _regNewPlate : _regOldPlate, caseSensitive: false, multiLine: false); | |
| _currentPlate.hasMatch(_plate) == true ? print('Placa válida') : print('Placa inválida'); | |
| } | |
| // Checking new model of plate | |
| checkNewPlate(true, 'ABC1D23'); | |
| // Checking old model of plate | |
| checkNewPlate(false, 'ABC-1234'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment