patternString static method
Validator that requires the field's value to match a regex pattern.
Note that if a Regexp is provided, the Regexp is used as is to test the values.
Validate that the field only contains alphabets
TextFormField(
decoration: InputDecoration(
labelText: 'Pattern r"^[A-Za-z]+\$"',
),
validator: Validators.patternString(
r"^[A-Za-z]+$", 'Only alphabets are allowed'),
),
Implementation
static FormFieldValidator<String> patternString(
String pattern, String errorMessage) {
return patternRegExp(RegExp(pattern), errorMessage);
}