1. Determine if the text is empty:
1 $ (". Commonverify"). blur (function() {2 if($.trim (this). Val ()) = = ') {3 $ ("#tips"). HTML ("cannot be empty"); 4 $ (this). focus ();} 5 });
$.trim () is the parentheses around which the string is removed.
2. Determine the phone number:
1 //determine if the phone number is correct2$ (". Mobil"). Blur (function(){3 if(! ($.trim ($ ( This). val ()) = = ")){4 if(!$( This). Val (). Match (/^1[3|4|5|8][0-9]\d{4,8}$/)){5$( This). focus ();6$ ("#tips"). HTML ("Phone number error");7}Else{8$ ("#tips"). HTML ("");9 }Ten}Else{ One$( This). focus (); A$ ("#tips"). HTML ("cannot be empty"); - } - }); the
3. Determine if the postal code is correct:
1 //determine if the ZIP code is correct2$ ("#postalCode"). Blur (function(){3 if(! ($.trim ($ ( This). val ()) = = ")){4 if(!$( This). Val (). Match (/^[1-9]\d{5}$/)){5$( This). focus ();6$ ("#tips"). HTML ("ZIP code error: 6 digits expected");7}Else{8$ ("#tips"). HTML ("");9 }Ten}Else{ One$( This). focus (); A$ ("#tips"). HTML ("cannot be empty"); - } -});
4. Determine if the ID card is correct:
1$ ("#idCard"). Blur (function() {2 varIdcard = $ ("#idCard"). Val ();3 varBo =/^ (\d{6}) (18|19|20)? (\d{2}) ([01]\d) ([0123]\d) (\d{3}) (\d| X)? $/. Test (Idcard);4 varYear = IDCARD.SUBSTR (6, 4);5 varmonth = Idcard.substr (10, 2);6 varDay = Idcard.substr (12, 2);7 8 if(! ($.trim ($ ( This). val ()) = = ")){9 if(Bo = =false|| Month > 12 | | Day > 31) {Ten One$ ("#tips"). HTML ("Please enter the correct ID number!") "); A}Else{ -$ ("#tips"). HTML (""); - } the}Else{ -$( This). focus (); -$ ("#tips"). HTML ("cannot be empty"); - } +});
5. Determine the bank card number:
1$ ("#bankCard"). Blur (function(){2 if(! ($.trim ($ ( This). val ()) = = ")){3 if(!$( This). Val (). Match (/^\d{19}$/)){4$( This). focus ();5$ ("#tips"). HTML ("Malformed, should be 19 digits");6}Else{7$ ("#tips"). HTML ("");8 }9}Else{Ten$( This). focus (); One$ ("#tips"). HTML ("cannot be empty"); A } - -})
JQuery Form Validation