开发者

Email regex validation javascript

I do understand the problems with validat开发者_Go百科ing emails but I wonder whether this would block anyone that has a legal email.

I was looking for a list of valid emails to test it myself but did not find any.

Anyone have an email that is valid but this regex thinks it's not?

emailRegex.test('Emailing@domain.aero')

Very long line:

emailRegex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.(([a-z]{2}|AERO|ARPA|ASIA|BIZ|CAT|COM|COOP|EDU|GOV|INFO|INT|JOBS|MIL|MOBI|MUSEUM|NAME|NET|ORG|PRO|TEL|TRAVEL|XN--0ZWM56D|XN--11B5BS3A9AJ6G|XN--3E0B707E|XN--45BRJ9C|XN--80AKHBYKNJ4F|XN--90A3AC|XN--9T4B11YI5A|XN--CLCHC0EA0B2G2A9GCD|XN--DEBA0AD|XN--FIQS8S|XN--FIQZ9S|XN--FPCRJ9C3D|XN--FZC2C9E2C|XN--G6W251D|XN--GECRJ9C|XN--H2BRJ9C|XN--HGBK6AJ7F53BBA|XN--HLCJ6AYA9ESC7A|XN--J6W193G|XN--JXALPDLP|XN--KGBECHTV|XN--KPRW13D|XN--KPRY57D|XN--LGBBAT1AD8J|XN--MGBAAM7A8H|XN--MGBAYH7GPA|XN--MGBBH1A71E|XN--MGBC0A9AZCG|XN--MGBERP4A5D4AR|XN--O3CW4H|XN--OGBPF8FL|XN--P1AI|XN--PGBS0DH|XN--S9BRJ9C|XN--WGBH1C|XN--WGBL6A|XN--XKC2AL3HYE2A|XN--XKC2DL3A5EE0H|XN--YFRO4I67O|XN--YGBI2AMMX|XN--ZCKZAH|XXX)(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)|(^$)/i;


Dominic Sayers has created a list of email edge cases that you could use to validate your test. You can find it here.

The valid address test@[IPv6:::], "test\ test"@iana.org or "test@io" are not accepted by your regex.


It's a beautiful expression, but soon to be relegated to the realm of obsolescence:

http://www.icann.org/en/topics/new-gtld-program.htm

Global Top Level Domains (yourbestfriend@worksfor.coke) are coming, and they'll break all of our scripts in a few years :)

Though, to answer your question, no, I was not able to break your email check using today's finite limit on "valid" domain extensions.


Here is the code for html input field and button field

<input input type="text" name="txtEmailId" id="txtEmailId" /> 
   <input type="submit" class="button" value="Suscribe" name="Suscribe" 
            onclick="javascript:ShowAlert()" />

Now add the below function to the header of your page

<script type="text/javascript">
 function ShowAlert() {
  var email = document.getElementById('txtEmailId');
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
        alert('Please provide a valid email address');
        email.focus;
        return false;
    }
    else {
        alert("Thanks for your intrest in us, Now you 
        will be able to receive monthly updates from us.");
        document.getElementById('txtEmailId').value = "";
    }
 }
 </script> 

Here you can find the article on this Email Validation in JavaScript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜