2

I do understand the problems with validating 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('[email protected]') 

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; 
2
  • You should check this topic stackoverflow.com/questions/201323/… Commented Aug 15, 2011 at 10:37
  • Please fix your title so that it describes the question, rather than just listing topics. Commented Aug 15, 2011 at 10:57

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the IPv6 reference - you must be the one non-network engineer actually thinking about this already :)
0

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 ([email protected]) 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.

Comments

0

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

2 Comments

This will fail with valid e-mail like Jean-Franç[email protected]
You can put your email validation regex according to your requirment.... this is just an example that validates a simple email like "[email protected]"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.