[Front end] jquery Verify mobile number, ID number, Chinese name

Source: Internet
Author: User

Validation:

Chinese name, cell phone number, ID card and address


HTML (form):

<formaction=""> <Divclass="Form-group"> <label> Name: </label> <inputId="Name"Type="Text"> </Div> <Divclass="Form-group"> <label> Mobile Number: </label> <inputId="Phone"Type="Text"> </Div> <Divclass="Form-group"> <label> ID: </label> <inputId="Identity"Type="Text"> </Div> <Divclass="Form-group"> <labelclass="Label-textarea"> Mailing Address: </label> <textareaId="Address"></textarea> </Div> <Pclass="Tip"> Please fill in the real name authentication information, so that the acceptance information can not be modified once submitted, please carefully fill out. </P> <Divclass="Btn-group"> <Buttonclass="btn btn-md btn-purple"Type="Reset"> Cancel </Button> <Buttonclass="btn btn-md btn-purple ml-20"Id="Submit"Type="button"> Submit </Button> </Div> </form>

jquery Validation:


The test () method determines whether the string matches the contents of the regular expression, and returns a Boolean value (True/false)


Verify that the Chinese name function ischinaname (name) {var pattern =/^[\u4e00-\u9fa5]{1,6}$/;
return pattern.test (name);  
    //Verify the mobile number function Isphoneno (phone) {var pattern =/^1[34578]\d{9}$/;  
return pattern.test (phone); //Verify ID function iscardno (card) {var pattern =/(^\d{15}$) | ( ^\d{18}$) | (^\d{17} (\d|  
   X|X) $)/; 
return pattern.test (card);

    }//Verify function Functions Formvalidate () {var str = ';
        The Judgment name if ($.trim (' #name '). Val ()). Length = = 0) {str = ' name not entered \ n ';
    $ (' #name '). focus ();
            else {if (Ischinaname $.trim ($ (' #name '). Val ())) = = False) {str = ' name is illegal \ n ';
        $ (' #name '). focus ();
        }//Judge mobile number if ($.trim (' #phone '). Val ()). Length = = 0) {str = ' mobile number not entered \ n ';
    $ (' #phone '). focus ();
           else {if (Isphoneno $.trim ($ (' #phone '). val ()) = = False) {str = ' cell phone number is incorrect \ n ';
        $ (' #phone '). focus (); }//Verify identity card if ($.trim $ (' #identiTy '). Val ()). Length = = 0) {str = ' ID number not entered \ n ';
    $ (' #identity '). focus ();
            else {if (Iscardno $.trim ($ (' #identity '). Val ())) = = False) {str = ' ID number is incorrect; \ n ';
        $ (' #identity '). focus ();
        }//Verify address if ($.trim (' #address '). Val ()). Length = = 0) {str = ' address not entered \ n ';
    $ (' #address '). focus ();
        ///If no error is submitted if (str!= ') {alert (str);
    return false;
    } else {$ ('. Auth-form '). Submit (); } $ (' #submit '). On (' click ', Function () {formvalidate ();});

I used in the project, thank you for your attention ~



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.