获取中括号中的内容:
public static string GetBracketsValue(string content)
{
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(@"(?i)(?<=\[)(.*)(?=\])");
return rgx.Match(content).Value;
}
字符串多空格截取
public static string[] RegexSplit(string optionSplit = "\\s+", string strSplit = "1234 56465 9 97879")
{
return System.Text.RegularExpressions.Regex.Split(strSplit, optionSplit,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
验证 ip地址:
public static bool IsIP(string ip)
{
return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
}
验证电话号码:
public bool IsTelephone(stringstr_telephone)
{
returnSystem.Text.RegularExpressions.Regex.IsMatch(str_telephone,@"^(\d{3,4}-)?\d{6,8}$");
}
验证手机号码:
public bool IsHandset(string str_handset)
{
returnSystem.Text.RegularExpressions.Regex.IsMatch(str_handset,@"^[1]+[3,5]+\d{9}");
}
验证身份证号:
public bool IsIDcard(stringstr_idcard)
{
returnSystem.Text.RegularExpressions.Regex.IsMatch(str_idcard,@"(^\d{18}$)|(^\d{15}$)");
}
验证输入为数字:
public bool IsNumber(stringstr_number)
{
returnSystem.Text.RegularExpressions.Regex.IsMatch(str_number,@"^[0-9]*$");
}
验证邮编:
public boolIsPostalcode(string str_postalcode)
{
returnSystem.Text.RegularExpressions.Regex.IsMatch(str_postalcode,@"^\d{6}$");
}