Country code + mobile phone number

Source: Internet
Author: User

China's mainland operators of mobile phone number standard format is: Country code + mobile phone number, such as: 8613912345678. Features such as the following:

1. length 13;
2. Begin with 86 of the country code;
3. Each digit of the mobile phone number is a number.
4. For example, the following mobile phone numbers are qualified: +86-13957177889, 8613957177889, +8613957177889, +86-139-5717-7889, 86-13957177889.

Please implement the function of the validity inference of the mobile number (note: Candidates do not need to pay attention to the authenticity of the mobile phone number, that is, such as 86123123456789 of the mobile phone number, we also think it is legal), requirements:

1. If the mobile phone number is qualified, return 0;
2. If the cell phone number is not valid, return 1;
3. Assuming that the cell phone number includes non-numeric characters, return 2;
4. Assuming that the mobile phone number is not 86, return 3;
5. In other cases, return 4.

Note: In addition to the success of the case, the above other legitimacy inference of the priority reduction, that is, the assumption that the length is not valid, directly return 1 can be, do not need to do other legitimacy inference.
<span style= "font-family:kaiti_gb2312;" > Code:</span> #include <stdio.h> #include <string.h>bool be (char str[])//start with ' + ' to return 1 {if (str[0]== ' + ') ) return 1;return 0;} BOOL _86 (char Str[],int len)//whether to start with 86 {if (BE (str)) {if (str[1]== ' 8 ' &&str[2]== ' 6 ') return 1;elsereturn 0;} Else{if (str[0]== ' 8 ' &&str[1]== ' 6 ') return 1;elsereturn 0;}} int Len (char str[],int Len) {int i,k=0;for (i=0;i<len;++i) {if (str[i]>= ' 0 ' &&str[i]<= ' 9 ') k++;} return k;} BOOL _fsz (char Str[],int len)//infer whether a non-numeric is included, is the return 1; {int i;if (is (str)) for (I=1;i<len;++i) {if (str[i]!= '-' &&! ( str[i]>= ' 0 ' &&str[i]<= ' 9 ')) return 1; Else{for (i=0;i<len;++i) {if (str[i]!= '-' &&! (    str[i]>= ' 0 ' &&str[i]<= ' 9 ')) return 1; }}return 0;} int MAIN () {char str[20];gets (str), int len=strlen (str), switch (len) {case 13:if (_86 (Str,len)) return 0;//else break; 14:if (_86 (Str,len)) if (BE (str) | | str[2]== '-') return 0;case 15:if (_86 (Str,len)) if (Be (str) &&str[3]== '-') RetuRN 0;case 17:if (_86 (Str,len)) if (Be (str) &&str[3]== '-' &&str[7]== '-' &&str[12]== '-') return 0;} if (Len (Str,len)!=13)//Length unqualified return 1;else{if (_fsz (Str,len)) return 2;else{if (_86 (Str,len)) return 4;elsereturn 3;}}} int main () {while (1) printf ("%d\n", Main ()); return 0;}

Country code + mobile phone number

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.