Transferred from: http://www.maiziedu.com/wiki/jquery/regular/
The basic regular
1, the creation of regular expressions
a) var checknum =/^[a-za-z0-9]+$/;
b) var re=new RegExp ("[" +s1+ "]", "G");
2. Common rules
A) User password:/^[a-za-z][a-za-z0-9_]{5,20}$/
b) Mail:/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/
c) Mobile:/^[\d]{5,20}$/
d) Other common validation: please Baidu
3. Method: Test
Case
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>jquery Ajax</title> <Scripttype= "Text/javascript"src= "Public/js/jquery-2.2.3.min.js"></Script></Head><Body><formAction=""> <label>User name:</label><spanID= "Check_username">Detection</span> <inputtype= "text"ID= "T_username"placeholder= "Please enter"/> <HR/> <label>Mailbox:</label><spanID= "Check_email">Detection</span> <inputtype= "text"ID= "T_email"placeholder= "Please enter"/> <HR/> <label>Cell phone:</label><spanID= "Check_phone">Detection</span> <inputtype= "text"ID= "T_phone"placeholder= "Please enter"/> <HR/></form></Body><Script> $(function () { //User name $("#check_username"). Click (function(){ varStr= $("#t_username"). Val (); varret= /^[a-za-z][a-za-z0-9_]{5,20}$/; if(Ret.test (str)) {alert ('OK'); }Else{alert ('wrong'); } }); //Mail $("#check_email"). Click (function(){ varStr= $("#t_email"). Val (); varret= /^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ \w-]+) +$/; if(Ret.test (str)) {alert ('OK'); }Else{alert ('wrong'); } }); //Mobile Phone $("#check_phone"). Click (function(){ varStr= $("#t_phone"). Val (); varret= /^[\d]{5,20}$/; if(Ret.test (str)) {alert ('OK'); }Else{alert ('wrong'); } }); });</Script></HTML>
Effect Demo diagram
Use of the jquery regular