private void button1_Click(object sender, EventArgs e)
{
if (IsPhone(txtSQLuser.Text))
{
MessageBox.Show("是手機號碼!");
}
else
{
if (IsPhoneHome(txtSQLuser.Text))
{
MessageBox.Show("是電話號碼!");
}
}
}
public bool IsPhoneHome(string str_Phone)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_Phone, @"(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,5}))?");//驗證電話號碼
}
public bool IsPhone(string str_Phone)
{ return System.Text.RegularExpressions.Regex.IsMatch(str_Phone, @"(?:13\d|15[1589])-?\d{5}(\d{3}|\*{3})"); //驗證手機號碼
}
public bool IsEmail(string str_Email)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");//驗證郵箱
}