Home>

If i want to verify your phone number,Then we need to know the phone number segment.

//Mobile number attribution support number segment:134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188

//China Unicom number attribution support number segment:130 131 132 145 155 156 176 186

//Telecom number attribution support number segment:133 153 177 180 181 189

//Mobile operator:170

mobile:2g paragraph (gsm):134-139, 150, 151, 152, 158-159;

Section 3g (td-scdma):157, 187, 188, 147.

Unicom:2g paragraph (gsm):130-132, 155-156;

3g paragraph (wcdma):185, 186.

telecommunications:

2g paragraph (cdma):133, 153;

Paragraph 3g (cdma2000):180, 189.

Can write a regular expression:var myreg =/^ (((13 [0-9] {1}) | (14 [0-9] {1}) | (17 [0] {1}) | (15 [0-3] {1 }) | (15 [5-9] {1}) | (18 [0-9] {1})) + \ d {8}) $/;<input type="text" name="phone" />

First introduce a jquery framework:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js">
</script>

Function to verify mobile phone number:

//Verify mobile phone number
     function vailphone () {
       var phone=jquery ("#​​phone"). val ();
       var flag=false;
       var message="";
       var myreg =/^ (((13 [0-9] {1}) | (14 [0-9] {1}) | (17 [0] {1}) | (15 [0-3] {1 }) | (15 [5-9] {1}) | (18 [0-9] {1})) + \ d {8}) $/;
       if (phone == "") {
         message="Mobile number cannot be empty!";
       } else if (phone.length!=11) {
         message="Please enter a valid mobile number!";
       } else if (! myreg.test (phone)) {
         message="Please enter a valid mobile number!";
       } else if (checkphoneisexist ()) {
         message="This mobile number is already linked!";
       } else {
           flag=true;
       }
       if (! flag) {
      //Prompt error effect
         //jquery("#phonediv").removeclass().addclass("ui-form-item has-error ");
         //jquery ("#​​phonep"). html ("");
         //jquery("#phonep").html("<i class=\ "icon-error ui-margin-right10 \"><\/i>"+ message);
         //jquery ("#​​phone"). focus ();
       } else {
            //Prompt the correct effect
         //jquery("#phonediv").removeclass().addclass("ui-form-item has-success ");
         //jquery ("#​​phonep"). html ("");
         //jquery("#phonep").html("<i class=\ "icon-success ui-margin-right10 \"><\/i>the phone number is available ");
       }
       return flag;
     }

Send a request to the background:

//Verify that the phone number exists
       function checkphoneisexist () {
         var phone=jquery ("#​​phone"). val ();
         var flag=true;
         jquery.ajax (
          {url:"checkphone?t =" + (new date ()). gettime (),            data:{phone:phone},            datatype:"json",               type:"get",               async:false,               success:function (data) {
               var status=data.status;
               if (status == "0") {
                 flag=false;
               }
             }
        });
        return flag;
       }

Java backend for verification:

@requestmapping (value="/checkphone", method=requestmethod.get)
  public void checkphone (httpservletrequest request, httpservletresponse response) {
    map<string, object>map=new hashmap<string, object>();
    try {
      string phone=request.getparameter ("phone");
      string status="0";
      //Write query logic,Find out if there is,Then marked as 1, otherwise marked as 0
            //usercellphoneauth usercellphoneauth=userservice.findusercellphoneauthbyphone (phone);
      //if (usercellphoneauth!=null) {
      //status="1";
      //}
      map.put ("status", status);
      string data=jsonobject.fromobject (map) .tostring ();
      response.getwriter (). print (data);
      response.getwriter (). flush ();
      response.getwriter (). close ();
    } catch (exception ex) {
      logger.error (ex.getmessage (), ex);
    }
  }
  • Previous Learn me about floating point precision in javascript
  • Next Follow me about the use of javascript's prototype