i have a regexp for password validation ( Regexp Java for password validation with extra special characters)
String pattern ="^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=!\\*_?|~(){}/<>:\"\',\\[\\]`;\\\\\\\\-])(?=\\S+$).{8,}$";
The issue with this is, if i say
"Xyz.123".matches(pattern);
This returns false
However, if i say
"Xyz.123$".matches(pattern);
This returns true
'.' is not a valid special characters in my case. But if my password has a valid special character along with '.' it returns true
You have \\\\S+
, which means "any non-space character." .
satisfies that. You also need the $
to satisfy the third pseudo-condition (lookahead). .
is not in that, but $
is.
EDIT: If you do not want any periods at all, change the last pseudo-condition to (?=[^\\\\s.]+$)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.