[数据库][C#]几个常用的正则表达式
1 Regex integer = new Regex("^[0-9]{1,}$"); // Pure numbers. 2 Regex letter = new Regex("^[A-Za-z]+$"); // Pure letters. 3 Regex character = new Regex("^[\u4e00-\u9fa5]+$"); // Pure characters. 4 Regex intLett = new Regex("^[A-Za-z0-9]+$"); // Numbers, letters, or both. 5 Regex charLett = new Regex("^[\u4e00-\u9fa5a-zA-Z]+$"); // Characters, letters, or both.
以下参考自:http://blog.csdn.net/huutu/article/details/49159895
1 //不能含有特殊字符; 2 Regex reg = new Regex(@"^[\u4e00-\u9fa5a-zA-Z]+$"); 3 Match m = reg.Match(name); 4 if (!m.Success) 5 { 6 UIManager.Instance.ShowTip("请输入中文或字母!"); 7 return; 8 }
其它常用:
匹配字符串全部是中文字符的正则表达式:
"^[\u4e00-\u9fa5]+$"
匹配字符串中包含中文字符的正则表达式:
"[\u4e00-\u9fa5]"
匹配字符串中以中文字符开头的正则表达式:
"^[\u4e00-\u9fa5]"
匹配字符串中以中文字符结尾的正则表达式:
"[\u4e00-\u9fa5]$"