当前位置:编程学习 > C#/ASP.NET >>

常用正则表达式 check

[csharp]
      private static Regex RegPhone = new Regex("^[0-9]+[-]?[0-9]+[-]?[0-9]{1}$"); 
private static Regex RegNumber = new Regex("^[0-9]+{1}$"); 
private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+{1}$"); 
private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+{1}$"); 
private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+{1}$"); //等价于^[+-]?\d+[.]?\d+$ 
private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info){1}$");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样  
private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");//是否有中文 

 一个例子:

 

[csharp]
#region 中文检测 
 
/// <summary> 
/// 检测是否有中文字符 
/// </summary> 
/// <param name="inputData"></param> 
/// <returns></returns> 
public static bool IsHasCHZN(string inputData) 

    Match m = RegCHZN.Match(inputData); 
    return m.Success; 
}    
 
#endregion 


摘自 keenweiwei的专栏
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,