Cell phone number legality judgment

Source: Internet
Author: User

Cell phone number legality judgment (20 points)

Problem Description:

China's mainland operators of mobile phone number standard format is: Country code + mobile phone number, for example: 8613912345678. Features are as follows:

1, 13 bits in length;

2, with 86 of the country code starts;

3, mobile phone number of each person is a number.

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

1) If the mobile phone number is valid, return 0;

2) If the phone number is not valid, return 1

3) If the phone number contains non-numeric characters, return 2;

4) If the mobile phone number does not begin with 86, return 3;

"Note" In addition to the success of the case, the above other legal judgment priority reduced. That is to say, if the length is not valid, return 1 directly, do not need to do other legal judgment.

Required implementation functions:

int verifymsisdn (char* inmsisdn)

"Input" char* inmsisdn, which represents the input mobile number string.

"Output" none

The result of the "return" judgment, type int.

Example

Input: inmsisdn = "869123456789"

Output: None

Returns: 1

Input: inmsisdn = "8813912345678"

Output: None

Returns: 3

Input: inmsisdn = "8613912345678"

Output: None

Returns: 0

1#include <stdio.h>2 intVERIFYMSISDN (Char*inmsisdn)3 {4     intlen,i;5     BOOLa[4];6     Const Char*p =inmsisdn;7Len =0;8      for(i=0; I <3; i++)9A[i] =false;Tena[3] =true; One     if(inmsisdn[0] =='8'&& inmsisdn[1] =='6') Aa[3] =false; -p++; -p++; theLen + =2; -      while(*p! =' /') -     { -         if(*p <'0'|| *p >'9') +a[2] =true; -p++; +len++; A     } at     if(Len! = -) -a[1] =true; -     if(!a[1] &&!a[2] &&!a[3]) -a[0] =true; -      for(i=0; I <4; i++) -         if(A[i]) in             returni; - } to intMain () + { -     Chars[ -]; thescanf"%s", s); *printf"%d\n", VERIFYMSISDN (s)); $}

Cell phone number legality judgment

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.