How can i check valid format of Aadharcard, driving licence and Pan Card in textform field in Flutter programmatically
CodePudding user response:
You can use regex to validate all types of patterns. Like Pancard has pattern like ABCDE111F. Aadhar card is just 12 digit number and so on.
CodePudding user response:
The fastest and easiest solution is to use a regex expression:
extension AadharNumberValidator on String {
bool isValidAadharNumber() {
return RegExp(
r'^[2-9]{1}[0-9]{3}\\s[0-9]{4}\\s[0-9]{4}$')
.hasMatch(this);
}
}
extension PanCardValidator on String {
bool isValidPanCardNo() {
return RegExp(
r'^[A-Z]{5}[0-9]{4}[A-Z]{1}$')
.hasMatch(this);
}
}
extension DrivingLicense Validator on String {
bool isValidLicenseNo() {
return RegExp(
r'^(([A-Z]{2}[0-9]{2})( )|([A-Z]{2}-[0-9]{2}))((19|20)[0-9][0-9])[0-9]{7}$')
.hasMatch(this);
}
}
And use extension of String for validate
TextFormField(
autovalidate: true,
validator: (input) => input.isValidAadharNumber() ? null : "Check your aadhar number",
)