手机,传真,邮箱正则表达式

手机号
/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/

/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/     手机号2018年最新

传真~
 /^(\d{3,4}-)?\d{7,8}$/

邮箱
^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$

代码:

if(string.IsNullOrEmpty(Tel_txtEdit.Text))
                {
                    errorProvider.SetError(Tel_txtEdit, "电话不能为空!");
                    return;
                }
                else
                {
                    Regex regx = new Regex("^(((0\\d{3}[\\-])?\\d{7}|(0\\d{2}[\\-])?\\d{8}))([\\-]\\d{2,4})?$"); //010-66667788
                    string Tel = Tel_txtEdit.Text.Trim();
                    Match m = regx.Match(Tel);
                    if(!m.Success)
                    {
                        errorProvider.SetError(Tel_txtEdit,"电话号码格式错误,请输入正确的格式如:xxx-xxxxxxxx");
                        return;
                    }
                    else
                    {
                        string TelSql = "select Tel from HR_Department where Tel='"+Tel+"' and DBCenter='" + GlobalSetting.LoginInfo.DBCenter + "'";
                        string db_Tel = (string)DBHelper.ExecuteScalar("server=***.***.***.***;database=AppDB;uid=***;pwd=******",TelSql);
                        if(!string.IsNullOrEmpty(db_Tel))
                        {
                            errorProvider.SetError(Tel_txtEdit,"此电话已经存在,请重新输入!");
                            return;
                        }
                        newHRDepartmentEntity.Tel = Tel;
                    }

 

你可能感兴趣的:(正则表达式)