js验证密码的正则表达式 JavaScript怎么写验证密码的正则表达式?
js\u9a8c\u8bc1\u5bc6\u7801\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u5b8c\u6574\u7684js\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a
//\u5f3a\uff1a\u5b57\u6bcd+\u6570\u5b57+\u7279\u6b8a\u5b57\u7b26
^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$ //\u4e2d\uff1a\u5b57\u6bcd+\u6570\u5b57\uff0c\u5b57\u6bcd+\u7279\u6b8a\u5b57\u7b26\uff0c\u6570\u5b57+\u7279\u6b8a\u5b57\u7b26
^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$
//\u5f31\uff1a\u7eaf\u6570\u5b57\uff0c\u7eaf\u5b57\u6bcd\uff0c\u7eaf\u7279\u6b8a\u5b57\u7b26^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$
//\u6821\u9a8c\u662f\u5426\u5168\u7531\u6570\u5b57\u7ec4\u6210function isDigit(s){var patrn=/^[0-9]{1,20}$/;if (!patrn.exec(s)) return falsereturn true
}//\u6821\u9a8c\u767b\u5f55\u540d\uff1a\u53ea\u80fd\u8f93\u51655-20\u4e2a\u4ee5\u5b57\u6bcd\u5f00\u5934\u3001\u53ef\u5e26\u6570\u5b57\u3001\u201c_\u201d\u3001\u201c.\u201d\u7684\u5b57\u4e32function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;if (!patrn.exec(s)) return falsereturn true}function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;if (!patrn.exec(s)) return falsereturn true}
//\u6821\u9a8c\u7528\u6237\u59d3\u540d\uff1a\u53ea\u80fd\u8f93\u51651-30\u4e2a\u4ee5\u5b57\u6bcd\u5f00\u5934\u7684\u5b57\u4e32Javascript\u4ee3\u7801function isTrueName(s){var patrn=/^[a-zA-Z]{1,30}$/;if (!patrn.exec(s)) return falsereturn true}}}//\u6821\u9a8c\u5bc6\u7801\uff1a\u53ea\u80fd\u8f93\u51656-20\u4e2a\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf
function isPasswd(s){var patrn=/^(\w){6,20}$/;if (!patrn.exec(s)) return falsereturn true}//\u6821\u9a8c\u666e\u901a\u7535\u8bdd\u3001\u4f20\u771f\u53f7\u7801\uff1a\u53ef\u4ee5\u201c+\u201d\u5f00\u5934\uff0c\u9664\u6570\u5b57\u5916\uff0c\u53ef\u542b\u6709\u201c-\u201d
function isTel(s){//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//\u6821\u9a8c\u624b\u673a\u53f7\u7801\uff1a\u5fc5\u987b\u4ee5\u6570\u5b57\u5f00\u5934\uff0c\u9664\u6570\u5b57\u5916\uff0c\u53ef\u542b\u6709\u201c-\u201d
function isMobil(s){var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//\u6821\u9a8c\u90ae\u653f\u7f16\u7801
function isPostalCode(s){//var patrn=/^[a-zA-Z0-9]{3,12}$/;var patrn=/^[a-zA-Z0-9 ]{3,12}$/;if (!patrn.exec(s)) return falsereturn true}//\u6821\u9a8c\u641c\u7d22\u5173\u952e\u5b57
function isSearch(s){var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,./?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.?]{0,19}$/;if (!patrn.exec(s)) return falsereturn true}function isIP(s) //by zergling{var patrn=/^[0-9.]{1,20}$/;if (!patrn.exec(s)) return falsereturn true}
\u3000\u3000/^(([A-Z])+|([a-z]+)|(\d+))$/.test("aaaaaaa")
\u6216\u8005
/^(([A-Z])+|([a-z]+)|(\d+))$/.test("AABBBB")
\u6216\u8005
/^(([A-Z])+|([a-z]+)|(\d+))$/.test("1111111")
\u90fd\u4f1a\u8fd4\u56detrue
\u8fd4\u56detrue\u5c31\u662f\u5bc6\u7801\u4e0d\u7b26\u5408\u89c4\u5219\u3002
/^(([A-Z])+|([a-z]+)|(\d+))$/.test("121AAV")
\u8fd9\u6837\u8fd4\u56defalse\u7684\u5c31\u662f\u9a8c\u8bc1\u901a\u8fc7\u7684
完整的js正则表达式:
//强:字母+数字+特殊字符
//中:字母+数字,字母+特殊字符,数字+特殊字符
^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$
//弱:纯数字,纯字母,纯特殊字符^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$
//校验是否全由数字组成function isDigit(s){var patrn=/^[0-9]{1,20}$/;if (!patrn.exec(s)) return falsereturn true
}//校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;if (!patrn.exec(s)) return falsereturn true}function isRegisterUserName(s){var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;if (!patrn.exec(s)) return falsereturn true}
//校验用户姓名:只能输入1-30个以字母开头的字串Javascript代码function isTrueName(s){var patrn=/^[a-zA-Z]{1,30}$/;if (!patrn.exec(s)) return falsereturn true}}}//校验密码:只能输入6-20个字母、数字、下划线
function isPasswd(s){var patrn=/^(\w){6,20}$/;if (!patrn.exec(s)) return falsereturn true}//校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
function isTel(s){//var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//校验手机号码:必须以数字开头,除数字外,可含有“-”
function isMobil(s){var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;if (!patrn.exec(s)) return falsereturn true}//校验邮政编码
function isPostalCode(s){//var patrn=/^[a-zA-Z0-9]{3,12}$/;var patrn=/^[a-zA-Z0-9 ]{3,12}$/;if (!patrn.exec(s)) return falsereturn true}//校验搜索关键字
function isSearch(s){var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^&()+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;if (!patrn.exec(s)) return falsereturn true}function isIP(s) //by zergling{var patrn=/^[0-9.]{1,20}$/;if (!patrn.exec(s)) return falsereturn true}以下是验证密码的正则表达式,其要求包含其中任意两种类型:数字、小写字母、大写字母、特殊字符(~!@#$%^\u0026*()_-+=)。``` ^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^\u0026*()_-+=]).{8,20}$ ```解释:- `^` 开始匹配- `(?=.*\\d)` 匹配任意数字- `(?=.*[a-z])` 匹配任意小写字母- `(?=.*[A-Z])` 匹配任意大写字母- `(?=.*[~!@#$%^\u0026*()_-+=])` 匹配任意特殊字符- `.{8,20}` 匹配长度在 8-20 之间的任意字符- `$` 结束匹配其中 `(?=.*…)`表示零宽度正预测先行断言,也就是向前检查是否有某种字符。
<p>
密码<input type="password" id=“pwd”>
</p>
验证密码就:
var pwd=docment.getElementById("pwd").value; //获取密码框里的元素
var reg="这里写你要求密码的正则表达式格式";
//例如密码要求5-10位字母数字下划线,那么正则式就是 var reg=/^\w{5,10}$/; (记住^开始和$不要漏了)
if(reg.test(pwd)){
return true;
)
var pa=/^(?=.{6,16}$)(?![0-9]+$)(?!.*(.).*\1)[0-9a-zA-Z]+$/;
把你允许的特殊字符放到[0-9a-zA-Z] 中
<script>
var userName='testName';//用户名
var t1="a-z",t2="A-Z",t3="0-9",t4="!@#%";//有什么特殊符号,修改T4的值
var r0="(?!.*"+userName+".*)",r1="(?=.*["+t1+"]+)",r2="(?=.*["+t2+"]+)",r3="(?=.*["+t3+"]+)",r4="(?=.*["+t4+"]+)";
var s1=r1+r2+r3+"["+t1+t2+t3+"]+",s2=r1+r2+r4+"["+t1+t2+t4+"]+",s3=r1+r3+r4+"["+t1+t3+t4+"]+",s4=r2+r3+r4+"["+t2+t3+t4+"]+",s5=r1+r2+r3+r4+"["+t1+t2+t3+t4+"]+";
var r=new RegExp("^"+r0+"(?:(?:"+s1+")|(?:"+s2+")|(?:"+s3+")|(?:"+s4+")|(?:"+s5+"))"+"$");
document.write(r + "<br/>");
document.write(r.test("asdf@#234AA"+userName+"234adfwe") + "<br/>");//false 因为包含用户名
document.write(r.test("1111111aaaaa") + "<br/>");//false 因为值满足2个条件
document.write(r.test("aaaaaAAAA") + "<br/>");//false 因为值满足2个条件
document.write(r.test("aaaaa!@#") + "<br/>");//false 因为值满足2个条件
document.write(r.test("aaaaa!@#11123") + "<br/>");//true
</script>
绛旓細瀹屾暣鐨js姝e垯琛ㄨ揪寮锛//寮猴細瀛楁瘝+鏁板瓧+鐗规畩瀛楃 ^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)(?![a-zA-z\d]+$)(?![a-zA-z!@#$%^&*]+$)(?![\d!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$ //涓細瀛楁瘝+鏁板瓧锛屽瓧姣+鐗规畩瀛楃锛屾暟瀛+鐗规畩瀛楃 ^(?![a-zA-z]...
绛旓細杩欎釜鏄姝e垯琛ㄨ揪寮锛歷ar reg = /^[\w]{6,12}$/ if(password.match(reg)){alert("The password is valid!");} ^鍙槸涓涓爣璁帮紝璇存槑姝e垯琛ㄨ揪寮忕殑寮濮嬶紝$涓虹粨鏉熺殑鏍囪锛屼笌{}涓殑鑼冨洿娌℃湁鍏崇郴銆傛鍒欒〃杈惧紡锛屽張绉瑙勫垯琛ㄨ揪寮锛岃绠楁満绉戝鐨勪竴涓蹇点傛鍒欒〃杈惧紡閫氬父琚敤鏉ユ绱佹浛鎹㈤偅浜涚鍚堟煇涓ā寮(...
绛旓細/^(?=.*\d)(?=.*[a-zA-Z]).{5,20}$/
绛旓細console.log("瀵嗙爜涓嶈兘鍖呭惈鈥渞oot鈥"); return"瀵嗙爜涓嶈兘鍖呭惈鈥渞oot鈥"; } } 鎵╁睍璧勬枡 js姝e垯琛ㄨ揪寮忛獙璇佸瘑鐮寮哄害,蹇呴』鍖呭惈鏁板瓧,澶у啓瀛楁瘝,灏忓啓瀛楁瘝,鐗规畩瀛楃鍥涢変笁 varregex=newRegExp('^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W...
绛旓細1銆侀鍏堟垜浠湪script涓紪鍐欏嚱鏁般2銆佷笅鍥句腑鐨勪唬鐮佸氨鏄垽鏂墜鏈哄彿鐮佷腑鏈閲嶈鐨勪唬鐮侊紝鎴戜滑渚濇杩涜瑙i噴銆3銆js姝e垯琛ㄨ揪寮test鏂规硶鐨勪娇鐢紝test鏂规硶鐨勮繑鍥炲兼槸甯冨皵鍊硷紝閫氳繃璇ュ煎彲浠ュ尮閰嶅瓧绗︿覆涓槸鍚﹀瓨鍦ㄤ簬姝e垯琛ㄨ揪寮忕浉鍖归厤鐨勭粨鏋滐紝濡傛灉鏈夊尮閰嶅唴瀹癸紝杩斿洖ture锛屽鏋滄病鏈夊尮閰嶅唴瀹硅繑鍥瀎alse锛岃鏂规硶甯哥敤浜庡垽鏂敤鎴疯緭鍏...
绛旓細^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$銆姝e垯琛ㄨ揪寮锛屽張绉瑙勫垯琛ㄨ揪寮锛屾槸璁$畻鏈虹瀛︾殑涓涓蹇点傛鍒欒〃杈惧紡閫氬父琚敤鏉ユ绱佹浛鎹㈤偅浜涚鍚堟煇涓ā寮(瑙勫垯)鐨勬枃鏈備竴銆佽捣婧 1銆佹鍒欒〃杈惧紡鐨勨滈蓟绁栤濇垨璁稿彲涓鐩磋拷婧埌绉戝瀹跺浜虹被绁炵粡绯荤粺宸ヤ綔鍘熺悊鐨勬棭鏈熺爺绌躲傜編鍥芥柊娉借タ宸炵殑Warren Mc...
绛旓細1鍒板涓猏x0d\x0a鈥?鈥 0涓垨鑰1涓猏x0d\x0a鈥淸 ]鈥 (涓涓暟鍒板彟涓涓暟涔嬮棿)鑷畾涔夊尮閰嶅唴瀹筡x0d\x0a鈥 |鈥濇垨鑰匼x0d\x0a 鈥渰}鈥漿鏈灏忎釜鏁帮紝鏈澶т釜鏁皚 娆℃暟\x0d\x0a渚嬪锛氶偖绠楠岃瘉锛歕x0d\x0aRegex r = new Regex(@"^[\w]+@[\w].[A-Z|a-z]$");...
绛旓細1 涓姝ュ埌浣姝e垯琛ㄨ揪寮锛(?=.*[0-9])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[A-Z]).{6,16} 2杩欐槸绌蜂妇娉曞啓鐨勬鍒锛歛 = '[a-z]+';b = '[0-9]+';c = '[-+_!@#$%^&*()]+';p = "/$a$b$c|$a$c$b|$b$a$c|$b$c$a|$c$a$b|$c$b$a/";3杩欐槸涓...
绛旓細杩欎釜瑕佺敤姝e垯+js鍒ゆ柇鏉ヤ綔姝e垯鍙互鍒ゆ柇闀垮害浠ュ強鏄惁涓哄瓧姣,浣嗘槸鏃犳硶鍒ゆ柇杈撳叆鏁版嵁鏄惁閲嶅鍜岃繛缁 姊﹂噷瀵讳綘鎴戜粬 | 鍙戝竷浜2013-05-27 涓炬姤| 璇勮 0 0 涓烘偍鎺ㄨ崘: 姝e垯琛ㄨ揪寮廫. 姝e垯琛ㄨ揪寮忛粸鎬庨杭琛ㄧず 姝e垯琛ㄨ揪寮徛*? 姝e垯琛ㄨ揪寮忛兊绠 浠涔堟槸姝e垯琛ㄨ揪寮 鏃ユ湡鏍煎紡鐨勬鍒欒〃杈惧紡 PHP閭姝e垯琛ㄨ揪寮 涔愯璐﹀彿瀵嗙爜鏄...
绛旓細瀵js姝e垯琛ㄨ揪寮 10 1.姝e垯琛ㄨ揪寮忔暟瀛楄寖鍥1-360,澶т簬绛変簬1灏忎簬绛変簬360,蹇呴』鏄鏁存暟銆2.姝e垯琛ㄨ揪寮忔暟瀛楄寖鍥1-5000,澶т簬绛変簬1灏忎簬绛変簬5000,鍙鏄暟瀛楀氨琛屻... 1. 姝e垯琛ㄨ揪寮 鏁板瓧鑼冨洿1-360,澶т簬绛変簬1灏忎簬绛変簬360,蹇呴』鏄鏁存暟銆2. 姝e垯琛ㄨ揪寮 鏁板瓧鑼冨洿 1-5000,澶т簬绛変簬1灏忎簬绛変簬5000,鍙鏄暟瀛楀氨琛屻