C#常用正则表达式

using System.Text.RegularExpressions;

namespace Common
{
///


/// 检查输入的判断
///

public static class ValidateInput
{
//是否是数字
public static bool IsInteger(string txt)
{
Regex objRegex = new Regex(@"[1]$");
return objRegex.IsMatch(txt);
}
//是否是邮箱地址
public static bool IsEmail(string txt)
{
Regex objRegex = new Regex(@"^\w+([-+.]\w+)
@\w+([-.]\w+).\w+([-.]\w+)$");
return objRegex.IsMatch(txt);
}
//是否是手机号码
public static bool IsMobile(string txt)
{
Regex objRegex = new Regex(@"[2][3578]\d{9}$");
return objRegex.IsMatch(txt);
}
//是否是汉字
public static bool IsChinese(string txt)
{
Regex objRegex = new Regex(@"[3]{0,}$");
return objRegex.IsMatch(txt);
}
}
}


  1. 0-9 ↩︎

  2. 1 ↩︎

  3. \u4e00-\u9fa5 ↩︎

posted @ 2020-02-16 22:36  zhujie-  阅读(201)  评论(0编辑  收藏  举报