C#中如何判断联系电话的合法性
string tel = tb_tel.Text.Trim();//联系电话
if (!string.IsNullOrEmpty(tb_tel.Text.Trim()))
{
try
{
//num = Convert.ToInt32(txtTEL.Text.Trim().ToString());
Convert.ToInt64(tb_tel.Text.Trim());
}
catch (Exception ex)
{
ASPxCallback1_save.JSProperties["cpmess"] = "输入的联系电话格式不正确!";
// tb_tel.SelectAll();
tb_tel.Focus();
return;
}
if (tb_tel.Text.Length != 11)
{
ASPxCallback1_save.JSProperties["cpmess"] = "联系电话长度必须是11位,请正确输入!";
//tb_tel.SelectAll();
tb_tel.Focus();
return;
}
if (!System.Text.RegularExpressions.Regex.IsMatch(tel, @"^((0?1[358]\d{9})|((0(10|2[1-3]|[3-9]\d{2}))?[1-9]\d{6,7}))$"))
{
ASPxCallback1_save.JSProperties["cpmess"] = "您输入的联系电话不存在或不合法!";
//txtTEL.SelectAll();
tb_tel.Focus();
return;
}
}
我还是会相信,星星会说话,石头会开花,穿过夏天的栅栏和冬天的风雪过后,你终会抵达。