1/21/2018

Javascript Email format validation checker, check @ and dots

Question

I have done some searching on how to capture email address top level domain name dots and the number of @ sign. Most codes I found returned true if I enter like.

testemail@domain.com.co.uk.gov.info.org

I want a maximum of two dots and one @ sign only which caters domain such as:

domain.co.uk
domain.gov.info
domain.info.org

and so on.


Answer


Below is a code I created that will caters your email validation needs.


If you want to increase the number of accepted dots (.) just increase the value 4.

Hope it helps.