Some time ago to deal with the verification of mobile phone, amount, decimal point and other verification. Recently done the page, and encountered a verification of the mailbox, the process is not much said, directly to see the code. Implementation key or regular, regular expression is very powerful. There is a chance to learn, but it is not easy to learn. Fortunately some of the commonly used, online can be found. But you know what you have to do!
The code is as follows |
Copy Code |
$ (function () { $ ("#email"). blur (function () { var Txt_value = $ (this). Val (); if (txt_value== "") { $ (this). val ("Please enter your email address") }else if (!) ( /^w+ ([.-]?w+) *@w+ ([.-]?w+) * (. w{2,3}) +$/.test (Txt_value))) { Alert ("Please enter a valid email address"); $ (this). Val (""); return false; }
}) }) |
Inside the form the Mailbox text box name and id attribute are all email. Add Mouse to move out events.
Cases
The code is as follows |
Copy Code |
Mailbox Verification if ($ ("#email"). val () = ") { $ ("#email"). focus (); Alert ("Please fill in your mailbox"); 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 ("Incorrect mailbox format, please fill in"); $ ("#email"). focus (); return False } |