电子邮件中的验证错误

时间:2015-01-21 05:44:11

标签: javascript

Javascript代码

//more code
function change() {
    var select = document.getElementById("slct");
    var divv = document.getElementById("container");
    var value = select.value;
    var toAppend='';
    for(i = 0; i < value; i++)
    {
        toAppend += '<p class="profile-name">*Tracker</p><input type="text" data-validation-email-message="Not a valid email id!" pattern=  "^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)" data-validation-pattern-message="Must be a valid email id" requiredclass="input-medium" name="tracker[]" placeholder="Email Address" required="required"/>&nbsp; <input type="text"  pattern="^[0-9]{1,10}" data-validation-pattern-message="Do not use special characters or numbers" placeholder="Contact No" name="contact_tracker[]"/>';
    }
    divv.innerHTML = toAppend;  return;
}
//more code

HTML代码

<select id="slct" onchange="change();">
    <option value="0" selected="selected">select</option>
    <option value="1"> 1 </option>
    <option value="2"> 2 </option>
    <option value="3"> 3 </option>
</select>

此处电子邮件总是给出错误,即根据验证模式

,给定输入字段是正确的,它总是给出错误

1 个答案:

答案 0 :(得分:0)

你的正则表达式是错误的。请使用此

/ ^([A-ZA-Z0-9 _.-])+ \ @(([A-ZA-Z0-9 - ])+。)+([A-ZA-Z0-9] {2- ,4})+ $ /