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);
}
}
C#常用的正则表达式的几种用法
最新推荐文章于 2025-07-29 11:21:14 发布
该博客内容包含一系列使用正则表达式进行验证的静态方法,如验证数字、身份证号、性别和邮箱。方法简洁明了,适用于字符串格式校验。

3598

被折叠的 条评论
为什么被折叠?



