积极答复者
C#验证手机号码

问题
答案
-
用正则表达式来校验,下面是实际项目中的一段代码:
/// <summary> /// 校验手机号码是否符合标准。 /// </summary> /// <param name="mobile"></param> /// <returns></returns> public static bool ValidateMobile(string mobile) { if (string.IsNullOrEmpty(mobile)) return false; return Regex.IsMatch(mobile, @"^(13|14|15|16|18|19)\d{9}$"); }
Please mark the post answered your question as the answer, and vote other helpful posts, so they will appear differently to other users for the same problem. 请将解决实际问题的帖子标记为“答案”,并给其他有帮助的帖子投票,这样其他人有同样问题的时候可以快速找到解决方案。谢谢!- 已建议为答案 Frank Xu LeiModerator 2010年7月5日 7:28
- 已标记为答案 KeFang Chen 2010年7月7日 1:56
全部回复
-
用正则表达式来校验,下面是实际项目中的一段代码:
/// <summary> /// 校验手机号码是否符合标准。 /// </summary> /// <param name="mobile"></param> /// <returns></returns> public static bool ValidateMobile(string mobile) { if (string.IsNullOrEmpty(mobile)) return false; return Regex.IsMatch(mobile, @"^(13|14|15|16|18|19)\d{9}$"); }
Please mark the post answered your question as the answer, and vote other helpful posts, so they will appear differently to other users for the same problem. 请将解决实际问题的帖子标记为“答案”,并给其他有帮助的帖子投票,这样其他人有同样问题的时候可以快速找到解决方案。谢谢!- 已建议为答案 Frank Xu LeiModerator 2010年7月5日 7:28
- 已标记为答案 KeFang Chen 2010年7月7日 1:56
-
用正则表达式来校验,下面是实际项目中的一段代码:
/// <summary> /// 校验手机号码是否符合标准。 /// </summary> /// <param name="mobile"></param> /// <returns></returns> public static bool ValidateMobile(string mobile) { if (string.IsNullOrEmpty(mobile)) return false; return Regex.IsMatch(mobile, @"^(13|14|15|16|18|19)\d{9}$"); } 确定是只检查中国的手机号吗?没有其它国家的?
Please mark the post answered your question as the answer, and vote other helpful posts, so they will appear differently to other users for the same problem. 请将解决实际问题的帖子标记为“答案”,并给其他有帮助的帖子投票,这样其他人有同样问题的时候可以快速找到解决方案。谢谢!
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
【老徐的博客】:http://www.cnblogs.com/frank_xl/
【WCF中文技术论坛】:微软WCF中文技术论坛
【WCF英文技术论坛】:微软WCF英文技术论坛