正则表达式

验证电话号码的主要代码如下:
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}$");
}

posted on 2018-06-07 16:05  愚公学编程  阅读(100)  评论(0编辑  收藏  举报