I see this mentioned now and then, and it's a bit unfortunate that the page doesn't mention the limitations of the code snippet as it produces somewhat incorrect results. (Well, both do, as they use the same regex.) It's simple to test, just go to the Wikipedia page for email addresses and test the valid and invalid ones:
https://en.wikipedia.org/wiki/Email_address#Examples. Yes, some of them are
very strange, but that doesn't make them less valid, or invalid. I ran them through
an online regex tool and got the result below. (For more strange examples, search the net.
Here's a list I found right away.)
I am fully aware that the snippet is absolutely fine for 99% of the cases, but I think it should be clarified that it's not 100% correct. I have no problem with anyone using it, as long as they understand this.
In reality there is only one way to validate an email address with 100% certainty: Send a test email to the entered address, with a link for the user to click.
How can i check for Valid Email ... to make sure its characters are not Less or greater than 10 characters
A valid address can be as short as 3 characters, as far as I can tell. Odds are against that you will ever encounter such an address obviously, but just picking 10 as a limit is just plain wrong. I'm sure that
[email protected] would agree with me.