问问题
165 次
2 回答
1
For my answer, I want to use a simpler regex similar to yours: [A-Z[^!]]+
, which means "At least once: (a character from A to Z) or (a character that is not '!').
Note that "not '!'" already includes A to Z. So everything in the outer character group([A-Z...
) is pointless.
Try [\p{Alpha}'-.]+
and compile the regex with the Pattern.UNICODE_CHARACTER_CLASS
flag.
于 2012-10-31T13:31:48.530 回答
0
Use: (?=.*[@#$%&\s]) - Return true when atleast one special character (from set) and also if username contain space.
you can add more special character as per your requirment. For Example:
String str = "k$shor";
String regex = "(?=.*[@#$%&\\s])";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
System.out.println(matcher.find()); => gives true
于 2012-10-31T14:07:07.920 回答