日期:2014-05-18 浏览次数:20760 次
/// <summary> /// 检查输入的电话号码是否符合要求 /// </summary> /// <param name="phoneNumber">输入的电话号码信息</param> /// <param name="phoneType">电话号码的类型,手机还是固话</param> /// <returns>5至8位固话,或前缀0574/021等区号(用-分割),或13XXXXXXXXX,15XXXXXXXXX,或前缀0的为真,不在前述情况列的为假</returns> public static bool PhoneNumberRegex(string phoneNumber, PublicUnit.PhoneType phoneType) { string regexString = ""; switch (phoneType) { case PublicUnit.PhoneType.tel: regexString = @"(^0[0-9]{2,3}\-[0-9]{5,8}$)|(^[0-9]{5,8}$)"; break; case PublicUnit.PhoneType.mobile: regexString = @"(^0{0,1}1[3,5,8]{1}[0-9]{9}$)"; break; } return Regex.IsMatch(phoneNumber, regexString); }
------解决方案--------------------
http://www.cnblogs.com/flyker/archive/2009/02/12/1389435.html