JavaScript Program to Validate An Email Address

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example: Using Regex

Output

The email address is valid
The email address is not valid

In the above program, the regular expression pattern

/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

checks if an email address is valid or not.

The test() method returns true if there is a match in the string with the regex pattern.

The regular expression (regex) describes a sequence of characters used for defining a search pattern.

To learn more about the regex, visit JavaScript Regular Expression.