Determine the legality of mobile phone number

Source: Internet
Author: User

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 requirements of mobile phone number legality judgment:
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


The C code is as follows:

#include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN 13#define SIZE 100int VERIFYMSISDN (char* inmsisdn); int main () {char *str = (char*) malloc (size*sizeof (char));p rintf ("Please input the Cellphone number: "); scanf ("%s ", str);p rintf (" The result is%d\n ", verifymsisdn (str)); return 0;} int verifymsisdn (char* inmsisdn) {int flag = 0;if (LEN = = strlen (inmsisdn)) {if (*inmsisdn = = ' 8 ' && * (inmsisdn+1) = = ' 6 ') flag = 1;while (*inmsisdn! = ') {if (*inmsisdn >= ' 0 ' && *inmsisdn <= ' 9 ') Inmsisdn++;elsereturn 2;} if (flag = = 1) return 0;elsereturn 3;} Elsereturn 1;}

Several test cases are used:





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.