正则验证数字
/// <summary>
/// 使用指定正则进行验证(只能输入数字)
/// </summary>
/// <param name="regex">正则表达式</param>
/// <param name="validateString">待验证字符</param>
/// <returns></returns>
public static bool RegexValidate(string regexString, string validateString)
{
Regex regex = new Regex(regexString);
return regex.IsMatch(validateString.Trim());
}
if ( RegexValidate("^[0-9]*$", msgphone) == true) //"^[0-9]*$"
{ }
else
{
MessageBox.Show("格式不正确!");
return;
}
浙公网安备 33010602011771号