package com.desigin.listening;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class 密码正则 {
public static void main(String[] args) {
String regx = "(?=.*[a-z])(?=.*\\d)(?=.*[#@!~%^&*])[a-z\\d#@!~%^&*]{6,16}";
Pattern pattern = Pattern.compile(regx);
String pwd = "1a2b3!1a2b3!1a2b3!";
Matcher m = pattern.matcher(pwd);
System.out.println(m.find());
}
}
var regUpper = /[A-Z]/;
var regLower = /[a-z]/;
var regNum = /[0-9]/;
var regTeShu =new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>~!@#¥……&*()——|{}【】‘;:”“'。,、?+-]");
var complex = 0;
if (regLower.test(this.editPasswordForm.newPass)) {
++complex;
}
if (regUpper.test(this.editPasswordForm.newPass)) {
++complex;
}
if (regNum.test(this.editPasswordForm.newPass)) {
++complex;
}
if(regTeShu.test(this.editPasswordForm.newPass)){
++complex;
}
if (complex < 3 || this.editPasswordForm.newPass.length < 8) {
this.$Message.error("密码长度不小于8位,包含数字、字母大、小写、符号中的至少3种")//iview中的一个提示框
return false
}else{
this.$Message.success("成功")//iview中的一个提示框
}
看到人家这样写,简单明了感觉挺好的