I created a login page and I need to add these things to my password. How do I do it with validation alert message?
Your regular expression should look like:
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$
Here is an explanation:
r'^
(?=.*[A-Z]) // should contain at least one upper case
(?=.*[a-z]) // should contain at least one lower case
(?=.*?[0-9]) // should contain at least one digit
(?=.*?[!@#\$&*~]).{8,} // should contain at least one Special character
$
Match above expression with your password string.Using this method-
String validatePassword(String value) {
Pattern pattern =
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~]).{8,}$';
RegExp regex = new RegExp(pattern);
print(value);
if (value.isEmpty) {
return 'Please enter password';
} else {
if (!regex.hasMatch(value))
return 'Enter valid password';
else
return null;
}
}