正则常用后台验证
验证用户为中文:
String passUserNO = serialLog.getBillKey().trim(); Pattern chinaP = Pattern.compile("^[\u4e00-\u9fa5]+"); Matcher chinaM = chinaP.matcher(passUserNO); boolean chinaKey = chinaM.matches(); if(chinaKey==true){ addActionError("用户总户号不能为中文!"); return businessDetails(); }
public static void test(){ Pattern pattern1 = Pattern.compile("\\(\\w+\\)"); Matcher matcher = pattern1.matcher("aaaa(bbb)aaaaaaaaa(bb)aaaaaa"); while(matcher.find()){ String str = matcher.group(); System.out.println("str:"+str); }