新项目可能用得到的代码,在这里先记录一下
通过正则筛注册框的输入,只允许输入,中文,英文,阿拉伯数字 空格 / - () % . : , 。 :()* # ?
package com.zj998;
public class Filter {
public static void main(String[] args) {
String qq = "生12345 /66(as)d-f:4";
//String regex = "[\\w\\u4e00-\\u9fa5\\/\\-\\(\\)\\%\\.\\:\\,\\。\\:\\(\\)\\*\\#\\?\\s]*";
//简化后
String regex = "[\\/\\-()%.:,。:()*#?\\s\\w\\u4e00-\\u9fa5]*";
boolean flag = qq.matches(regex);
if (flag) {
System.out.println(qq + "...is ok");
} else {
System.out.println(qq + "... 不合法");
}
}
}
写的有些繁琐了