This is building on my previous post on how to use regular expressions with j Query. Update 12/05/13: Separated into versions for testing.//reported to validate incorrectly: [email protected] as true /[A-Z0-9._% -] @[A-Z0-9-] .
Last month I wrote about regular expressions in Java, today I’ll show you how to use regular expression in Java Script to validate email address.A valid email is of the format: [email protected] The name can be a set of ‘atoms’ separated by dots. single or double quotes and any character inside the quotes Now, to the domain part. MUSEUM .travel, .international or even .vermögensberatung For example all the following email addresses are valid: Source The sad truth is that despite the complex regular expression validation, the email may not be existing, so can still be invalid for practical purposes.In its simplest form like this: [email protected], the atoms can contain 1. Most email validation checks assumes that the top level domain can have up to 4 characters. You have just validated the format – not its existence.Having a-z and A-Z means that both lowercase and uppercase letters are allowed.indicates the minimum and maximum number of characters.The only way to truly validate the email address is to send an email to that address and request the user to confirm by clicking on a unique link (or entering a confirmation code)Remember, if the user’s intention is to enter an invalid email address, she can do it so easily whether you have the most tough validation or not.
I would like to have feedback from my blog readers.
Please post your feedback, question, or comments about this article.
The best option is to ask the user to type their e-mail in twice and if you MUST use a regex checker, then tell the user that their e-mail address does not appear to be valid and ask if they are sure they typed it right.
Even go so far as to point out WHAT did not check out in the regexp check, but do NOT stop them from submitting the form.
Here is the code to validate email address in Java Script using regular expression.