password static method
FormFieldValidator<String>
password({
- String? errorMessage,
- int minLength = 4,
- int? maxLength,
- bool shouldContainNumber = false,
- bool shouldContainSpecialChars = false,
- bool shouldContainCapitalLetter = false,
- bool shouldContainSmallLetter = false,
- Function? reason,
- String onNumberNotPresent()?,
- String onSpecialCharsNotPresent()?,
- String onCapitalLetterNotPresent()?,
Implementation
static FormFieldValidator<String> password({
String? errorMessage,
int minLength = 4,
int? maxLength,
bool shouldContainNumber = false,
bool shouldContainSpecialChars = false,
bool shouldContainCapitalLetter = false,
bool shouldContainSmallLetter = false,
Function? reason,
String Function()? onNumberNotPresent,
String Function()? onSpecialCharsNotPresent,
String Function()? onCapitalLetterNotPresent,
}) {
return (fieldValue) {
var mainError = errorMessage;
if (Validator.isPassword(
fieldValue,
minLength: minLength,
maxLength: maxLength,
shouldContainSpecialChars: shouldContainSpecialChars,
shouldContainCapitalLetter: shouldContainCapitalLetter,
shouldContainSmallLetter: shouldContainSmallLetter,
shouldContainNumber: shouldContainNumber,
isNumberPresent: (present) {
if (!present) mainError = onNumberNotPresent!();
},
isCapitalLetterPresent: (present) {
if (!present) mainError = onCapitalLetterNotPresent!();
},
isSpecialCharsPresent: (present) {
if (!present)
mainError = onSpecialCharsNotPresent != null
? onSpecialCharsNotPresent()
: "Password must contain special character";
},
)) {
return null;
} else {
return mainError ?? "Password must match the required format";
}
};
}