Test questions (cell phone number legality 4)

Source: Internet
Author: User

Cell phone number legality judgment

Problem Description: The standard format of mobile phone number of Chinese mainland operators 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 cell phone number legality judgment

(Note: Candidates do not need to pay attention to the authenticity of mobile phone numbers

In other words, such as 86123123456789 of the mobile phone number, we also think it 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. Other words

If you determine the length is not legal, directly return 1, do not need to do other legal judgment.

Required implementation function: int s int verifymsisdn (char* inmsisdn)

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

"Output" none

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


Input: inmsisdn = "869123456789"

Output: None

Returns: 1

Input: inmsisdn = "88139123456789"

Output: None

Returns: 3

#include <string>using namespacestd;intVERIFYMSISDN (Char*inmsisdn) {unsigned Len=strlen (INMSISDN); if(Len! = -)        return 1;  for(Unsigned i=0; i<len;i++)    {      if(inmsisdn[i]<'0'|| Inmsisdn[i]>'9')          return 2; }    if(inmsisdn[0]!='8'|| inmsisdn[1]!='6')        return 3; return 0;}

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.