12345678910111213141516171819202122232425262728293031323334
|
#region 常用数据验证的封装,数字字符的验证 /// <summary> /// 常用数据验证的封装,数字字符的验证 /// </summary> /// <param name="inputVal">需要验证的数值【字符串,或者数字】</param> /// <param name="type">类型为哪一个验证</param> /// <returns>如果验证成功则返回True,否则返回false</returns> public static bool IsMatch( string inputVal, int type) { switch (type) { case 0: return Regex.IsMatch(inputVal, @"^[1-9]d*$" ); case 1: return Regex.IsMatch(inputVal, @"^-?\d+$" ); case 2: return Regex.IsMatch(inputVal, @"^[A-Za-z0-9]+$" ); case 3: return Regex.IsMatch(inputVal, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$" ); case 4: return Regex.IsMatch(inputVal, @"^[\u4e00-\u9fa5]{0,}$" ); case 5: return Regex.IsMatch(inputVal, @"^[0-9]+(.[0-9]{1,3})?$" ); case 6: return Regex.IsMatch(inputVal, @"^[A-Za-z]+$" ); case 7: return Regex.IsMatch(inputVal, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" ); case 8: return Regex.IsMatch(inputVal, @"((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)" ); default : return true ; } } #endregion |