Products
GG网络技术分享 2025-03-18 16:15 2
正则表达式表示:包括大写字母、小写字母、数字、符号至少2种,密码长度8-32位。
这个怎么写呢?求救!
http://www.cnblogs.com/cdinc/p/5793142.html
w3c讲的很详细,可以看看
public void matchString(String str){
if(str.length()>=8&&str.length()<=32){
int findCount=0;
String findLolCase = \\\"[a-z]\\\";
String findUpCase = \\\"[A-Z]\\\";
String findNumber= \\\"[0-9]\\\";
String findOther = \\\"[^0-9a-zA-Z]\\\";
if(Pattern.compile(findLolCase).matcher(str).find()){
findCount++;
}
if(Pattern.compile(findUpCase).matcher(str).find()){
findCount++;
}
if(Pattern.compile(findNumber).matcher(str).find()){
findCount++;
}
if(Pattern.compile(findOther).matcher(str).find()){
findCount++;
}
if(findCount>=2){
System.out.println(\\\"输入合法\\\");
}else{
System.out.println(\\\"输入的字符种类不合法\\\");
}
}else{
System.out.println(\\\"输入的字符创长度不合法\\\");
}
}
//分开匹配,匹配上了findCount就加1,它等于几就是满足了几种方式。若长度不满足则没必要匹配。
这是java匹配。要是js匹配的话就直接百度就ok了。
规则表达式(regular expression)
1、比如网站要求你输入的QQ号为5~12位数字
2、电话号码必须是010-12345678或0731-88032131这样的字符串
3、比如Email邮箱验证
4、比如过滤关键字或者过滤HTML标签
5、比如发表评论的时候只允许中文评论
6、比如去除字符串首尾空格
---正则是不是必须--- 正则虽然不是必须的,但是用了正则后,会让你的代码更少,效率更高,可读写更好
语法(公式)
Demand feedback