朝阳市网站建设,html静态页面,单位做后盾工作总结,全网推广费用释放双眼#xff0c;带上耳机#xff0c;听听看~#xff01;最近朋友有个用户名验证#xff0c;要求字母、数字、字符任意两种组合即可#xff0c;让我帮写个正则验证#xff0c;现在正则验证如下#xff1a;/*** 判断是否匹配正则** param regex 正则表达式* param inp…释放双眼带上耳机听听看~最近朋友有个用户名验证要求字母、数字、字符任意两种组合即可让我帮写个正则验证现在正则验证如下/*** 判断是否匹配正则** param regex 正则表达式* param input 要匹配的字符串* return {code true}: 匹配{code false}: 不匹配*/public static boolean isMatch(final String regex, final CharSequence input) {return input ! null input.length() 0 Pattern.matches(regex, input);}public static boolean isTest(CharSequence input) {String regex ^(?![0-9]$)(?![a-zA-Z]$)[A-Za-z0-9\W]{1,}$;// Pattern compile Pattern.compile(regex);// Matcher matcher compile.matcher(input.toString());// return matcher.find();return isMatch(regex, input);}测试Log.i(, abc12/., RegexUtils.isTest(abc12/.,));Log.i(, abc12 RegexUtils.isTest(abc12));Log.i(, abc.,/ RegexUtils.isTest(abc.,/));Log.i(, 123.,/ RegexUtils.isTest(123.,/));Log.i(, 123.,asdasd/ RegexUtils.isTest(123.,asdasd/));Log.i(, ,./123.,asdasd/ RegexUtils.isTest(123.,asdasd/));Log.i(, asdas,./123 RegexUtils.isTest(sdas,./123));Log.i(, 1234adsfa RegexUtils.isTest(1234adsfa));Log.i(, 。123sfdwe][0989//.;;[ RegexUtils.isTest(。123sfdwe][0989//.;;[));Log.i(, abc RegexUtils.isTest(abc));输出结果如下:: abc12/.,true: abc12true: abc.,/true: 123.,/true: 123.,asdasd/true: ,./123.,asdasd/true: asdas,./123true: 1234adsfatrue: 。123sfdwe][0989//.;;[true: abcfalse正则说明String regex ^(?![0-9]$)(?![a-zA-Z]$)[A-Za-z0-9\W]{1,}$;^ 匹配一行的开头位置(?![0-9]$) 预测该位置后面不全是数字(?![a-zA-Z]$) 预测该位置后面不全是字母[A-Za-z0-9\W]{1,} 由1位数字、字母、符号中任意两种组成$ 匹配行结尾位置