jquery verification of mobile phone numbers and formatting examples

Source: Internet
Author: User
Tags relative

We commonly used to verify the phone number of JS

--jquery Mobile phone Number verification

Cell Phone verification

function Ismobil (s)

{

//var reg=/^ ((13[0-9)) | ( 15[^4,\D]) | (18[0,5-9]) \d{8}$/;

var reg=/^1\d{10}$/;

if (!reg.exec (s)) {return

false;

}

return true;

}

Here we have a brief list of issues to be noted:
* Input box, can only enter numbers;
* In the process of input to display the contents of the input synchronously;
* Determine whether the input mobile phone number is in the correct format;
* To judge the place where the mobile phone belongs;

1, page structure

<! doctype html> 
The operation of the mobile phone number through the structure of the code we can easily find our corresponding operations, such as input code or paste code, etc. function ckphonelast (n) {    if (
n.value.length!=11) {        $ (' #phone_showtip '). HTML ("Please enter the correct phone number");     }else{        var partten = /^1 [3,5,8]\d{9}$/;          if (Partten.test (N.value)) {  
              ckbelong (N.value);         }else{//is not the cell phone number        
     $ (' #phone_showtip '). HTML ("Please enter the correct phone number"); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}    &nbsp}} function ckphone (n) { 
   $ (' #phone_showtip '). HTML ("");     $ ("#phone_belong"). HTML ("");        var ck=
False   &nBsp; n.value=n.value.replace (/\d/g, "");     if (n.value.length>11) {       //can only input 11 digits  
       n.value=n.value.substring (0,11); &NBSP;&NBSP;&NBSP;&NBSP}     if (n.value.length<=3) {      
In order to display the previous table         $ (' #phone_showtip '). HTML (n.value); &NBSP;&NBSP;&NBSP;&NBSP}     if (n.value.length>3) {      
  $ (' #phone_showtip '). HTML (n.value.substring (0,3)). Append (" "). Append (N.value.substring (3)); &NBSP;&NBSP;&NBSP;&NBSP}     if (n.value.length>7) {         $ (' #phone_showtip '). HTML (n.value.substring (0,3)). Append (" "). Append (n.value.substring (3,7)).
Append (" "). Append (n.value.substring (7)); &NBSP;&NBSP;&NBSP;&NBSP}     if (n.value.length==11) {        var partten = /^1[3,5,8]\d{9}$/;           if (Partten.test (N.value)) {        
        ck=true;         }else{//is not the cell phone number        
     $ (' #phone_showtip '). HTML ("Please enter the correct phone number");
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}     }     if (CK) {
        ckbelong (N.value); &NBSP;&NBSP;&NBSP;&NBSP}}

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.