C#常用的正则表达式的几种用法

该博客内容包含一系列使用正则表达式进行验证的静态方法,如验证数字、身份证号、性别和邮箱。方法简洁明了,适用于字符串格式校验。

public class Verification
{
public static bool IsNumber(string txt)//判断是不是数字
{
Regex objRegex = new Regex(@"1KaTeX parse error: Expected 'EOF', got '}' at position 55: …(txt); }̲ public…");
return regex.IsMatch(txt);
}
public static bool IsID(string txt)//判断是不是数字
{
Regex regex = new Regex(@"2\d{3}KaTeX parse error: Expected 'EOF', got '}' at position 52: …(txt); }̲ public…");
return objRegex.IsMatch(txt);
}
public static bool IsGender(string txt)//判断是不是男或者女
{
Regex objRegex = new Regex(@"^男|女KaTeX parse error: Expected 'EOF', got '}' at position 55: …(txt); }̲ public…");
return objRegex.IsMatch(txt);
}
public static bool IsEmail(string txt)//判断是不是邮箱
{
Regex objRegex = new Regex(@"^\w+([-+.]\w+)
@\w+([-.]\w+).\w+([-.]\w+)KaTeX parse error: Expected 'EOF', got '}' at position 55: …(txt); }̲ public…");
return regex.IsMatch(txt);
}
}


  1. 0-9 ↩︎

  2. 1-9 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值