请问如何判断输入的数据为英文字母,汉字或者是数字? 请教各位大虾:请问如何判断输入的数据为英文字母,汉字或者是数字? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private const string IS_NUMBER = @"(^[0-9]+$)"; private const string IS_YYYYMM_ICON = @"(^[1][8-9][0-9][0-9]/[0][1-9]+$)|(^[1][8-9][0-9][0-9]/[1][0-2]+$)|(^[2-9][0-9][0-9][0-9]/[0][1-9]+$)|(^[2-9][0-9][0-9][0-9]/[1][0-2]+$)"; private const string IS_YYYYMM = @"(^[1][8-9][0-9][0-9][0][1-9]+$)|(^[1][8-9][0-9][0-9][1][0-2]+$)|(^[2-9][0-9][0-9][0-9][0][1-9]+$)|(^[2-9][0-9][0-9][0-9][1][0-2]+$)"; private const string IS_HALF_WORD = @"(^(([!-/:-@[-`{-~])|([a-zA-Z0-9]))+$)"; public ComStyleCheck() { } /// <summary> /// regular expression check function /// </summary> /// <param name="regEx">expression</param> /// <param name="itemValue">check item</param> /// <returns>OK : true / NG : false</returns> //Regular Expression check public static bool IsRegEx(string regExValue, string itemValue) { try { //Get Regular Expression Regex regex = new System.Text.RegularExpressions.Regex(regExValue); if (regex.IsMatch(itemValue)) { return true; } else { return false; } } catch (Exception) { return false; } } /// <summary> /// maxlength check /// </summary> /// <param name="textForCheck"></param> /// <param name="maxLength"></param> /// <returns></returns> public static bool CheckStringLengthValid(string textForCheck,int maxLength) { int length = 0; char c; for(int i = 0; i < textForCheck.Length; i++) { c = textForCheck[i]; if (( c < 128 ) || ((c > 65376 )&&(c < 65440 ))) { length++; } else { length +=2; } } if(length > maxLength) { return false; } else { return true; } } #region number, decimal, money check /// <summary> /// is nember /// </summary> /// <param name="itemValue">check text</param> /// <returns>OK : true / NG : false</returns> //Number Check public static bool IsNumber(string itemValue) { return (IsRegEx(IS_NUMBER, itemValue)); } /// <summary> /// is Decimail /// </summary> /// <param name="decItem"></param> /// <returns></returns> //Decimail Check public static bool IsDecimail(string decItem) { try { decimal.Parse(decItem); } catch { return false; } return true; } //Check Money Value public static bool CheckMoneyValue(string sourceText, int numberPoint, int decimalPoint) { double d; if ( decimalPoint < 0 ) { return false; } else { if(sourceText.StartsWith(".") || sourceText.EndsWith(".")) { return false; } //Number Styles Check if ( Double.TryParse( sourceText, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d) ) { //check Value About decimalPoint string checkValue = sourceText.Replace(",", ""); if ( decimalPoint > 0 && checkValue.IndexOf('.')>0) { if ( (checkValue.Split('.'))[0].Length > numberPoint || (checkValue.Split('.'))[1].Length > decimalPoint ) { return false; } } else { //if xxx.00 if(checkValue.EndsWith(".00")) { numberPoint = numberPoint + 3; } if ( checkValue.Length > numberPoint ) { return false; } } } else { return false; } } return true; } validator控件里写正则表达式比如:只能输入英文,中文,数字,下划线和短横线 ^[-_a-zA-Z0-9\u4e00-\u9fa5]+$ 已知一个一个数据库实例名,如何得到它的服务名称? c# 中的 访问限定符 都有哪些 权限是?? 100分求助:如何编写一个C#程序,实现在一个网站里自动提交数据? C#中操作指针的问题 求高手解答? 用StreamWriter写文件时,“访问被拒绝” ,我的系统是2003的 关于路径 关于存储过程的调用 LinkLabel控件的,如何在点击之后打开某个网址? 高分请教!搜索一些数据,然后读入数据库 关于DataGrid的问题 求助.Net代码编辑过程中的问题~~~
private const string IS_YYYYMM_ICON = @"(^[1][8-9][0-9][0-9]/[0][1-9]+$)|(^[1][8-9][0-9][0-9]/[1][0-2]+$)|(^[2-9][0-9][0-9][0-9]/[0][1-9]+$)|(^[2-9][0-9][0-9][0-9]/[1][0-2]+$)";
private const string IS_YYYYMM = @"(^[1][8-9][0-9][0-9][0][1-9]+$)|(^[1][8-9][0-9][0-9][1][0-2]+$)|(^[2-9][0-9][0-9][0-9][0][1-9]+$)|(^[2-9][0-9][0-9][0-9][1][0-2]+$)";
private const string IS_HALF_WORD = @"(^(([!-/:-@[-`{-~])|([a-zA-Z0-9]))+$)"; public ComStyleCheck()
{
} /// <summary>
/// regular expression check function
/// </summary>
/// <param name="regEx">expression</param>
/// <param name="itemValue">check item</param>
/// <returns>OK : true / NG : false</returns>
//Regular Expression check
public static bool IsRegEx(string regExValue, string itemValue)
{
try
{
//Get Regular Expression
Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
if (regex.IsMatch(itemValue))
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
} /// <summary>
/// maxlength check
/// </summary>
/// <param name="textForCheck"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
public static bool CheckStringLengthValid(string textForCheck,int maxLength)
{
int length = 0;
char c; for(int i = 0; i < textForCheck.Length; i++)
{
c = textForCheck[i];
if (( c < 128 ) || ((c > 65376 )&&(c < 65440 )))
{
length++;
}
else
{
length +=2;
}
} if(length > maxLength)
{
return false;
}
else
{
return true;
}
} #region number, decimal, money check
/// <summary>
/// is nember
/// </summary>
/// <param name="itemValue">check text</param>
/// <returns>OK : true / NG : false</returns>
//Number Check
public static bool IsNumber(string itemValue)
{
return (IsRegEx(IS_NUMBER, itemValue));
} /// <summary>
/// is Decimail
/// </summary>
/// <param name="decItem"></param>
/// <returns></returns>
//Decimail Check
public static bool IsDecimail(string decItem)
{
try
{
decimal.Parse(decItem);
}
catch
{
return false;
} return true;
} //Check Money Value
public static bool CheckMoneyValue(string sourceText, int numberPoint, int decimalPoint)
{
double d; if ( decimalPoint < 0 )
{
return false;
}
else
{
if(sourceText.StartsWith(".") || sourceText.EndsWith("."))
{
return false;
}
//Number Styles Check
if ( Double.TryParse(
sourceText,
System.Globalization.NumberStyles.Any,
System.Globalization.NumberFormatInfo.InvariantInfo, out d)
)
{
//check Value About decimalPoint
string checkValue = sourceText.Replace(",", ""); if ( decimalPoint > 0 && checkValue.IndexOf('.')>0)
{
if ( (checkValue.Split('.'))[0].Length > numberPoint ||
(checkValue.Split('.'))[1].Length > decimalPoint
)
{
return false;
}
}
else
{
//if xxx.00
if(checkValue.EndsWith(".00"))
{
numberPoint = numberPoint + 3;
} if ( checkValue.Length > numberPoint )
{
return false;
}
}
}
else
{
return false;
}
} return true;
}
只能输入英文,中文,数字,下划线和短横线
^[-_a-zA-Z0-9\u4e00-\u9fa5]+$