要求:
大小写字母、数字、除空格以外的其他特殊字符,且满足三种以上即可
/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,20}$/ && /^[^\s]*$/
目前用了两个正则校验,有谁能帮忙整合一下

正则整合,大小写字母、数字、除空格以外的其他特殊字符,且满足三种以上
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- liliangxia 2021-09-16 13:59关注
验证一下整合就是2个规则中间加个
|
符号,但是太长了<body> <div class="mydiv"> <input id="myinput" type="text" onkeyup="check(this.value);"> <div id="err" style="background-color: #ccc; min-height: 30px;"></div> </div> </body> <script> /* 数字 小写 特殊 数字 大写 特殊 大 小写 数字 大 小写 特殊 */ let reg1 = /(?=.*\d)(?=.*[~!@#$%^&*()_+`\-\=<>?,:;\/'".\\\|[\]{}])((?=.*[a-z])|(?=.*[A-Z]))/ let reg2 = /(?=.*[a-z])(?=.*[A-Z])((?=.*\d)|(?=.*[~!@#$%^&*()_+`\-\=<>?,:;\/'".\\\|[\]{}]))/ let reg3 = /\s/g function check(value) { if (reg1.test(value) || reg2.test(value)) { document.getElementById("err").innerHTML= "正确"; } else { document.getElementById("err").innerHTML= "错误"; } } </script>
解决 1无用