Js:
$ ("#email"). blur (function () {//Gets the value of the element corresponding to the ID, minus its left and right space var email = $.trim ($ (' #email '). Val ());//Verify the mailbox format of the JS regular expression var Isemail =/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/; Empties the data in the display layer by $ ("#emailMess"). HTML (""); if (email = = "") { $ ("#emailMess"). HTML ("<font color= ' Red ' >" + "Mailbox cannot be empty" + "</font>");} else if (!) ( Isemail.test (email)) { $ ("#emailMess"). HTML ("<font color= ' Red ' >" + "Mailbox format is incorrect" + "</font>");} else{ //Here you can send JSON data to the background and return the validation result }
HTML:
<script type= "Text/javascript" src= "js/jquery-1.10.1.js" ></script><div class= "li" > < Label for= "Email" class= "label" ><span class= "Flag" >* </span> mailbox:</label> <input type= " Text "Name=" Userinfo.email "id=" email "placeholder=" Please enter a valid mailbox "size=" "maxlength="/><label id= "emailmess" class= "Label_mess" ></label></div>
Example of jquery+ Regular expression validation mailbox format