Jquery-verified email verification instance

Source: Internet
Author: User
Tags valid email address

In jq, email verification is the same as in javascript. We use regular expressions such as/^ \ w + ([\.-]? \ W +) * @ \ w + ([\.-]? \ W +) * (\. \ w {2, 3}) + $/. test (txt_value) is difficult. There is no difference between the method and js.

Some time ago, verification was performed on the phone number, amount, and decimal point. Recently, I encountered another verification email address when I was working on the page. I didn't talk about it much, but I went straight to the code. The key to implementation is regular expressions, which are powerful. It is not easy to learn well if you have the opportunity. Fortunately, you can find them online. But you must understand it ~~

The Code is as follows: Copy code

$ (Function (){

$ ("# Email"). blur (function (){
Var txt_value = $ (this). val ();
If (txt_value = ""){
$ (This). val ("Enter your email address ")
} Else if (! (/^ W + ([.-]? W +) * @ w + ([.-]? W +) * (. w {2, 3}) + $/. test (txt_value ))){
Alert ("enter a valid Email Address ");
$ (This). val ("");
Return false;
}

})

})

The name and id attributes of the mailbox text box in the form are email. Add the mouse removal event.

Example

The Code is as follows: Copy code

// Email Verification
If ($ ("# email"). val () = "){
$ ("# Email"). focus ();
Alert ("Enter your email address ");
Return false;
} Else {
Var val = $ ("# email"). val ();
If (val. match (/^ [a-z0-9] + ([. _] * [a-z0-9] +) * @ [a-z0-9] + ([_.] [a-z0-9] +) + $/gi ))
{Return true };
Alert ("the email format is incorrect. Please enter it again ");
$ ("# Email"). focus ();
Return false
}

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.