【发布时间】:2014-08-26 18:07:22
【问题描述】:
我想要一个接受输入字符(A..Z 或 a..z)但不接受数字和特殊字符的正则表达式。 我写了这个方法和这些模式,但它不起作用:
public static Pattern patternString = Pattern.compile("\\D*");
public static Pattern special = Pattern.compile("[!@#$%&*,.()_+=|<>?{}\\[\\]~-]");
public static boolean checkString(String input) {
boolean bool_string = patternString.matcher(input).matches();
boolean bool_special = !special.matcher(input).matches();
return (bool_string && bool_special);
}
如果输入为:hello、table、Fire、BlaKc,checkString 应该返回 true,等等。
checkString 应返回 false:10、tabl_e、+、hel/lo等
我该怎么做?谢谢
【问题讨论】: