JavaScript Mailbox Validation Code Analysis

Source: Internet
Author: User

One of the simplest of this mailbox authentication does not verify mailbox length and legality, such as input "I'm @fdd." Hello, yes, you can.

The code is as follows Copy Code

function Is_email (str)
{if (Str.indexof ("@") ==-1) | | (Str.indexof (".") ==-1))
{

return false;
}
return true;
}

The above example simply determines if the user has entered a character that has @ and "." If not, then the email address is not valid, so if I enter

The code is as follows Copy Code
Fdafafsfsafdsa@fsafdsa@.fafdafsa

This can also be verified by the following, we use validation to do a mailbox verification

The code is as follows Copy Code

function Test ()
{
          var temp = document.getElementById ("Text1");
          //Validation of e-mail
            var myreg =/^ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+. [A-za-z] {2,3}$/;
           if (!myreg.test (temp.value))
     {
                alert (' Tip NN Please enter a valid e_mail! ');
               Myreg.focus ();
                return false;
    }
}

It's a little bit stronger than the top, and he can pass.

The code is as follows Copy Code
Fsafsa@fafa.fdsf

This can also be verified if we want to enter only as abc@qq.com

The code is as follows Copy Code

var emailreg = "/^w+ (-w+) | (. w+)) *@[a-za-z0-9]+ ((. | -) [a-za-z0-9]+] *. [a-za-z0-9]+$/];
var ee = "xwz@126.com";
var rege = new RegExp (Emailreg);

This is probably OK, because there are too many domain names, so we do not need to limit the suffix.

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.