JavaScript Mailbox Address verifier

Source: Internet
Author: User
Tags valid email address

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.