判断手机号是否合法编程c++

求思路+代码
为防止用户胡乱输入手机号或者粗心导致输入错误,系统通常会判断用户填写的手机号是否合法。合法的手机号需要满足下述几点要求:

1、字符长度为11位;2、首个字符为1;3、全部都为数字;

例:

不合法:1234567、23456737211、1234254@158、……

合法:13911810905、……

除上述3点要求外不考虑其他,请编写程序判定手机号是否合法,如果合法将变量手机号是否合法设定为1,否则设定为0。
求思路和代码




#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    if(len!=11||s[0]!='1') goto emm;
    for(int i=0;i<len;i++)
    {
        if(!(s[i]-48>=0&&s[i]-48<=9)) goto emm;
    }
    cout<<"yes";
    return 0;
    emm: cout<<"no";
}

#include <iostream>
#include <cstring>
using namespace std;
int IsLegal(char str[])
{
    if(strlen(str)==11 && str[0]==49)
    {
        for(int i=1; i<strlen(str); i++)
        {
            if(str[i]<48 || str[i]>57)
                return 0;
        }
        return 1;
    }
    return 0;
}
int main()
{
    char str[100]= {'\0'};
    gets(str);
    cout<<IsLegal(str)<<endl;
    return 0;
}

正则表达式了解下