JAVA Regex for password validation issue -
i have regexp password validation ( regexp java password validation special characters)
string pattern ="^(?=.*[0-9])(?=.*[a-z])(?=.*[a-z])(?=.*[@#$%^&+=!\\*_?|~(){}/<>:\"\',\\[\\]`;\\\\\\\\-])(?=\\s+$).{8,}$"; the issue is, if
"xyz.123".matches(pattern); this returns false
however, if
"xyz.123$".matches(pattern); this returns true
'.' not valid special characters in case. if password has valid special character along '.' returns true
you have \\s+, means "any non-space character." . satisfies that. need $ satisfy third pseudo-condition (lookahead). . not in that, $ is.
edit: if not want periods @ all, change last pseudo-condition (?=[^\\s.]+$)
Comments
Post a Comment