using System; using System.Text.RegularExpressions; namespace Zhaizj.Framework { /// /// 封装了几个常用的正则表达式 /// public class RegPattern { //public static readonly String Email = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"; /// /// 网址的正则表达式 /// //public static readonly String Url = @"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$"; public static readonly string Url = @"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$"; // http://msdn.microsoft.com/en-us/library/ms998267.aspx /// /// email 正则表达式 /// public static readonly String Email = @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$"; //public static readonly String Url = @"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$"; /// /// 货币值(小数)的正则表达式 /// public static readonly String Currency = @"^\d+(\.\d\d)?$"; //1.00 /// /// (负数)货币值(小数)的正则表达式 /// public static readonly String NegativeCurrency = @"^(-)?\d+(\.\d\d)?$"; //-1.20 /// /// html 页面中图片的正则表达式,获取<img src="" /> 的src部分 /// public static readonly String Img = "(?<= /// 检查 input 字符串是否和指定的正则表达式匹配 /// /// 需要检查的字符串 /// 正则表达式 /// public static Boolean IsMatch( String input, String pattern ) { return Regex.IsMatch( input, pattern); } } }