JavaScript Tutorial e-mail address verification Program
Validateemail ()
Next we want to see the email address if the user input is true. This means that the input data
Must contain at least one @ symbol and one point (. )。 In addition, @ must never be the first word in an e-mail address
Characters, the last point must be at least one character after the @ sign.
First we check any area of the email that the user entered. Next, we use regular expressions
and test () methods to check the areas of compliance. Also, we will use the trim () function, which will cut lead over
A string blank. This will not be perfect for verification-there may be a break below it does not meet the solution-but usually not good enough.
function Trim (s)
{
Return S.replace (/^s+|s+$/, "");
}
function Validateemail (FLD) {
var error= "";
var tfld = trim (fld.value); Value of field
With whitespace trimmed off
var emailfilter =/^[^@]+@[^@.] +. [^@]*ww$/;
var illegalchars=/[() <>,;:\ " []]/ ;
if (Fld.value = "") {
Fld.style.background = ' yellow ';
error = "You didn ' t enter email ADDRESS.N";
} else if (!emailfilter.test (TFLD)) { //test Email for
Illegal characters
fld.style.background = ' yellow ';
error = "Please enter a valid email ADDRESS.N";
} else if (Fld.value.match (Illegalchars)) {
Fld.style.background = ' yellow ';
error = "The email address contains illegal CHARACTERS.N";
} else {
fld.style.background = ' white ';
& nbsp; }
return error;
}