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