JQuery Form Validation

Source: Internet
Author: User
Tags jquery form validation

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.