English 中文(简体)
Regex 电子邮件核实错误——使用Javales
原标题:Regex email verification error - using JavaScript
//if HTML5 input email input is not supported
if(type ==  email ){    
    if(!Modernizr.inputtypes.email){ 
         var emailRegEx = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9-])+.+([a-zA-Z0-9]{2,4})+$/;              
         if( !emailRegEx.test(value) ){ 
            this.focus();
            formok = false;
            errors.push(errorMessages.email + nameUC);
            return false;
        }
    }
}

这是我检查电子邮件格式是否正确时的javascript regex。 但是,当我自己尝试时,就没有任何错误。 它没有检查,也没有检查结果。 我做了什么错误?

最佳回答

你们需要使用实际上适合电子邮件地址的雷管。 你的目前是完全破碎的,因为它获得了吨的有效地址。

http://www.erra-expressions.info/email.html。 更详细描述和论证为什么某一院子根本不是一种好的想法。

Anyway, here s one that probably fits for your needs:

[a-z0-9!#$%& *+/=?^_`{|}~-]+(?:.[a-z0-9!#$%& *+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

这里指的是经常表达。 in:

如果我们利用双重引述和方括号来忽略辛塔克斯,我们就更实际地执行了第2822号行政指示。 在目前实际使用的所有电子邮件地址中,该地址仍为99.99%。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签