Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于html的正则表达式_Javascript_Regex_Html - Fatal编程技术网

Javascript 用于html的正则表达式

Javascript 用于html的正则表达式,javascript,regex,html,Javascript,Regex,Html,如果我的模式与正则表达式匹配,我希望我的页面显示一条消息,但我不知道这为什么没有任何作用 html: 输入密码: 密码必须介于8-16个字符之间,包含大写、小写、数字和特殊字符 js: function reqMetVal(){ var pwfs=document.getElementById(“pword1”).value; var re=“^(?=..[A-Z])(?=.[A-Z])(?=.[0-9])(?=.?[\+\=\,\[\]\\\\\\\`,\[\]\\\\\\\\\\\\\\

如果我的模式与正则表达式匹配,我希望我的页面显示一条消息,但我不知道这为什么没有任何作用

html:


输入密码:
密码必须介于8-16个字符之间,包含大写、小写、数字和特殊字符

js:

function reqMetVal(){
var pwfs=document.getElementById(“pword1”).value;
var re=“^(?=..[A-Z])(?=.[A-Z])(?=.[0-9])(?=.?[\+\=\,\[\]\\\\\\\`,\[\]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
如果(pwfs.匹配(重新)){
DIMR=“满足要求”;
}否则如果(pwfs.length<1){
DIMR=“”;
}
否则{
DIMR=“未满足要求”;
}
document.getElementById(“reqMeeting”).innerHTML=DIMR;
}

您没有在任何地方调用您的函数…请使用正斜杠作为正则表达式分隔符。强烈建议编写多个单独的验证检查,而不是大量的正则表达式,即检查字符串长度,检查是否存在大写字母,检查特殊字符等将使您的维护更加清晰一千倍,而且由于前瞻正则表达式的复杂性,可能会更快。@SarveshKumarSingh我有一个名为allFunctions()的函数,我正在调用该函数,其中看起来是这样的<代码>函数allFunctions(){passwordValidation();reqMetVal();}@AvinashRaj这是什么意思?
<div class="third">
        <label> Enter Password: </label>
        <input type="text" name="pword1" class="iBox" id="pword1" onmouseout="HideToolTip()" onmouseover="ShowToolTip()" onkeyup="allFunctions()" placeholder="choose a password" autocomplete="off">
        <p id="tooltipbox">Password must be between 8-16 characters, contain an uppercase, lowercase, number and special character</p>
</div>
function reqMetVal(){
    var pwfs = document.getElementById("pword1").value;
    var re = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\\\+\=\.,\[\]_£|\`¬':\;\~{}<>()#?!\@$\%^&*-]).{8,20}$";

    if(pwfs.match(re)){
        DIMR = "Requirements MET";

    }else if (pwfs.length < 1){
        DIMR = "";
    }
    else{
        DIMR = "Requirements NOT MET";
    }
    document.getElementById("reqMeeting").innerHTML = DIMR;
}