static class phoneVerification { /// <summary> /// 验证是否为正确的手机号码 /// </summary> /// <param name="phone"></param> /// <returns></returns> static bool CheckMobliePhoneV2(string phone) { //电信手机号码正则 string dianxin = @"^[3578][01379]\d{8}$"; Regex dReg = new Regex(dianxin); //联通手机号码正则 string liantong = @"^[34578][01256]\d{8}$"; Regex tReg = new Regex(liantong); //移动手机号码正则 string yidong = @"^(134[012345678]\d{7}|[34578][012356789]\d{8})$"; Regex yReg = new Regex(yidong); if(dReg.IsMatch(phone)|| tReg.IsMatch(phone)|| yReg.IsMatch(phone)) { return true; } return false; } /// <summary> /// 判断是否为空 /// </summary> /// <returns></returns> static bool CheckIsEmpty(string Text) { return string.IsNullOrEmpty(Text); } /// <summary> /// 判断是否为数字 /// </summary> /// <returns></returns> static bool CheckIsNumber(string Text) { return Regex.IsMatch(Text, @"^[0-9]*$"); } /// <summary> /// 判断是否为11位数字,且首位为1 /// </summary> /// <param name="Text"></param> /// <returns></returns> static bool CheckIsPhoneNum(string Text) { return Regex.IsMatch(Text, @"^1\d{10}$"); } }
手机号码验证一般使用 CheckIsPhoneNum()方法验证,只要判断首位为1,其余10位为数字即可;再严格点的可以使用CheckMobliePhoneV2()方法,支持国内的三大运营商的号码段。