var regex = mobile: /^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/;//手机号码
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;//邮箱
//手机号正则判断
string _Result = "";
string _Pattern = @"(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})";
Match m = Regex.Match(txtUserMobile.Text, _Pattern);
if (m.Groups.Count > 1)//表示能匹配到有效的手机号码 比如为:13016752109 不包含区号
{
_Result = m.Groups[0].Value;
}
else
{
_Pattern = @"(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,5}))?";
m = Regex.Match(txtUserMobile.Text, _Pattern);
if (m.Groups.Count > 1)//表示能匹配到有效电话号码 有效格式为:区号(2-3位)-电话号码(7-8位)-分机号(3-5位) 分机号可选
{
_Result = m.Groups[0].Value;
}
}
if (_Result == "")
{
msg += "无效电话号码请重新输入! ";
}
//邮箱正则判断
//验证 E-mail 格式
string regexEmail = "\\w{1,}@\\w{1,}\\.\\w{1,}";
System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace|System.Text.RegularExpressions.RegexOptions.Multiline)| System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regEmail = new System.Text.RegularExpressions.Regex(regexEmail, options);
string email = txtUserMail.Text;
if (!regEmail.IsMatch(email))//email 填写符合正则表达式 "\\w{1,}@\\w{1,}\\.\\w{1,}"
{
msg = "邮箱格式不正确!";
}