Example of Validation Of Form Email Or Mail With Javascript
Javascript / / July 04, 2021
Many times we are presented with the need to validate that in a certain field of our form an address of correct email or email. For this we have to validate that the format is correct, that is, it includes an @ and a domain. There are many functions for that and most make use of the function indexOF () which may be unreliable in this approval.
It exists in javascript (as in other languages) the use of regular expressions that will help us to validate a form the correct format of an address from email, the example of email validation shown below:
Code:
function valEmail (value) {
re = / ^ [_ a-z0-9 -] + (. [_ a-z0-9 -] +) * @ [a-z0-9 -] + (. [a-z0-9 -] +) * (. [az] {2,3}) $ /
if (! re.exec (value)) {
return false;
} else {
return true;
}
}
The result of this function is Boolean, that is, it tells us if the format that we have entered is true or false, in order to use this function it must be inside "
Code:
Function example to validate email address in javascript