正则表达式在.net中的应用—新手工作笔记

.net中的正则表达式应引入System.Text.RegularExpressions命名空间

该空间下有Regex类,实例化该类时写入正则表达式

Regex regex = new Regex("正则表达式");

if(regex.IsMatch("要验证的字符串")){

  sucess!

}else{

  error!

}

常用的正则表达式:

纯数字:^[0-9]*$

纯字母:^[a-z,A-Z]*$

email:^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$

身份证:^\\d{15}|\\d{}18$

转载于:https://www.cnblogs.com/maomaoBlog/archive/2010/03/10/1682261.html

猜你喜欢

转载自blog.csdn.net/weixin_34321977/article/details/93273339
今日推荐