又是在
www.asp.net上找到的.因为其很简单并且作者也是直接了当把代码拿上来了,所以就不翻译了
代码如下
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Text.RegularExpressions;
namespaceCoreWebLibrary.Text.RegularExpressions
{
/**////<summary>
///AutilityclasscontainingfrequentlyusedRegularExpressionPatterns
///andtwoutilitymethodstoseeifapassedstringconformstothedesignated
///pattern.
///</summary>
publicclassPatterns
{
publicconststringEMAIL=@"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
publicconststringUS_ZIPCODE=@"^\d{5}$";
publicconststringUS_ZIPCODE_PLUS_FOUR=@"^\d{5}((-|\s)?\d{4})$";
publicconststringUS_ZIPCODE_PLUS_FOUR_OPTIONAL=@"^\d{5}((-|\s)?\d{4})?$";
/**////<summary>
///PermissiveUSTelephoneRegex.Doesnotallowextensions.
///</summary>
///<example>
///Allows:324-234-3433,3242343434,(234)234-234,(234)234-2343
///</example>
publicconststringUS_TELEPHONE=@"^([\(]{1}[0-9]{3}[\)]{1}[\.||\-]{0,1}|^[0-9]{3}[\.|\-|]?)?[0-9]{3}(\.|\-|)?[0-9]{4}$";
/**////<summary>
///Thismatchesaurlinthegenericformat
///scheme://authority/path?query#fragment
///</summary>
///<example>
///Allows:http://www.yahoo.com,https://www.yahoo.com,ftp://www.yahoo.com
///</example>
publicconststringURL=@"^(?<Protocol>\w+):\/\/(?<Domain>[\w.]+\/?)\S*$";
/**////<summary>
///Thismatchesanipaddressintheformatxxx-xxx-xxx-xxx
///eachgroupofxxxmustbelessthanorequalto255
///</summary>
///<example>
///Allows:123.123.123.123,192.168.1.1
///</example>
publicconststringIP_ADDRESS=@"^(?<First>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Second>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Third>2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?<Fourth>2[0-4]\d|25[0-5]|[01]?\d\d?)$";
/**////<summary>
///Thismatchesadateintheformatmm/dd/yy
///</summary>
///<example>
///Allows:01/05/05,12/30/99,04/11/05
///Doesnotallow:01/05/2000,2/2/02
///</example>
publicconststringDATE_MM_DD_YY=@"^(1[0-2]|0[1-9])/(([1-2][0-9]|3[0-1]|0[1-9])/\d\d)$";
/**////<summary>
///Thismatchesadateintheformatmm/yy
///</summary>
///<example>
///Allows:01/05,11/05,04/99
///Doesnotallow:1/05,13/05,00/05
///</example>
publicconststringDATE_MM_YY=@"^((0[1-9])|(1[0-2]))\/(\d{2})$";
/**////<summary>
///Thismatchesonlynumbers(nodecimals)
///</summary>
///<example>
///Allows:0,1,123,4232323,1212322
///</example>
publicconststringIS_NUMBER_ONLY=@"^([1-9]\d*)$|^0$";
/**////<summary>
///Thismatchesanystringwithonlyalphacharactersupperorlowercase(A-Z)
///</summary>
///<example>
///Allows:abc,ABC,abCd,AbCd
///Doesnotallow:AC,abc!,(a,b)
///</example>
publicconststringIS_ALPHA_ONLY=@"^[a-zA-Z]+$";
/**////<summary>
///Thismatchesanystringwithonlyuppercasealphacharacter(A-Z)
///</summary>
publicconststringIS_UPPER_CASE=@"^[A-Z]+$";
/**////<summary>
///Thismatchesanystringwithonlylowercasealphacharacter(A-Z)
///</summary>
publicconststringIS_LOWER_CASE=@"^[a-z]+$";
/**////<summary>
///Ensuresthestringonlycontainsalpha-numericcharacters,and
///notpunctuation,spaces,linebreaks,etc.
///</summary>
///<example>
///Allows:ab2c,112ABC,ab23Cd
///Doesnotallow:AC,abc!,a.a
///</example>
publicconststringIS_ALPHA_NUMBER_ONLY=@"^[a-zA-Z0-9]+$";
/**////<summary>
///ValidatesUSCurrency.Requires$sign
///Allowsforoptionalcommasanddecimal.
///Noleadingzeros.
///</summary>
///<example>Allows:$100,000or$10000.00or$10.00or$.10or$0or$0.00
///Doesnotallow:$0.10or10.00or10,000</example>
publicconststringIS_US_CURRENCY=@"^\$(([1-9]\d*|([1-9]\d{0,2}(\,\d{3})*))(\.\d{1,2})?|(\.\d{1,2}))$|^\$[0](.00)?$";
/**////<summary>
///Matchesmajorcreditcardsincluding:Visa(length16,prefix4);
///Mastercard(length16,prefix51-55);
///DinersClub/CarteBlanche(length14,prefix36,38,or300-305);
///Discover(length16,prefix6011);
///AmericanExpress(length15,prefix34or37).
///Savesthecardtypeasanamedgrouptofacilitatefurthervalidation
///againsta"cardtype"checkboxinaprogram.
///All16digitformatsaregrouped4-4-4-4withanoptionalhyphenorspace
///betweeneachgroupof4digits.
///TheAmericanExpressformatisgrouped4-6-5withanoptionalhyphenorspace
///betweeneachgroupofdigits.
///Formattingcharactersmustbeconsistant,i.e.iftwogroupsareseparatedbyahyphen,
///allgroupsmustbeseparatedbyahyphenforamatchtooccur.
///</summary>
publicconststringCREDIT_CARD=@"^(?:(?<Visa>4\d{3})|(?<Mastercard>5[1-5]\d{2})|(?<Discover>6011)|(?<DinersClub>(?:3[68]\d{2})|(?:30[0-5]\d))|(?<AmericanExpress>3[47]\d{2}))([-]?)(?(DinersClub)(?:\d{6}\1\d{4})|(?(AmericanExpress)(?:\d{6}\1\d{5})|(?:\d{4}\1\d{4}\1\d{4})))$";
/**////<summary>
///Matchessocialsecurityinthefollowingformatxxx-xx-xxxx
///wherexisanumber
///</summary>
///<example>
///Allows:123-45-6789,232-432-1212
///</example>
publicconststringSOCIAL_SECURITY=@"^\d{3}-\d{2}-\d{4}$";
/**////<summary>
///Matchesx,xwherexisaname,spacesareonlyallowedbetweencommaandname
///</summary>
///<example>
///Allows:christophersen,eric;christophersen,eric
///Notallowed:christophersen,eric;
///</example>
publicconststringNAME_COMMA_NAME=@"^[a-zA-Z]+,\s?[a-zA-Z]+$";
privatePatterns()
{
}
/**////<summary>
///Checkstoseeifthepassedinputhasthepassedpattern
///</summary>
///<paramname="pattern">Thepatterntouse</param>
///<paramname="input">Theinputtocheck</param>
///<returns>Trueiftheinputhasthepattern,falseotherwise</returns>
publicstaticboolHasPattern(stringpattern,stringinput)
{
RegexregEx=newRegex(pattern);
returnregEx.IsMatch(input);
}
/**////<summary>
///Checksthepassedinputtomakesureithasallthepatternsinthe
///passedpatternsarray
///</summary>
///<paramname="patterns">Arrayofpatterns</param>
///<paramname="input">Stringvaluetocheck</param>
///<returns>Trueiftheinputhasallofthepatterns,falseotherwise.</returns>
publicstaticboolHasPatterns(string[]patterns,stringinput)
{
for(inti=0;i<patterns.Length;i++)
{
if(Patterns.HasPattern(patterns[i],input)==false)
returnfalse;
}
returntrue;
}
}
分享到:
相关推荐
正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式正则表达式
老外写的一个正则表达式测试工具,还是非常不错的 小巧实用
是老外用JAVA写的一个正则表达式测试工具,里面内置了许多有用的功能.
存成.asp文件,执行,你用ASPHTTP抓内容的时候用这个很爽,当然自己要改进一下了<%Option ExplicitFunction stripHTML(strHTML)‘Strips the HTML tags from strHTML Dim objRegExp, strOutput...“<.+?>...
老外写的表达式求值封装类,可计算三角函数,反三角函数,普通公式等等. 代码修改方便,很适合扩展. 支持参数重新赋值计算等等. 演示: #include "Express.h" #include "ExpValue.h" #include "VarValue.h" void main() ...
老外写的ADO封装类,超全面,使用简单。经过长期测试,使用中相当稳定。
老外写的图表类,可以生成饼图、柱图等图表,非常漂亮。
可以用于进行url转发的ISAPI 筛选器,老外的作品! 很好用,www.4inlook.com里的很多无后缀的url都是用的这个, 只要会写正则表达式配置下就可以了
老外写的一个flash时间类,还比较准确了哟。。。
几个老外写的ado,dao,odbc数据库操作类的vc代码
一个老外写的HtmlEditor,很不错!!
老外写的焊接机器人程序.zip西门子PLC编程实例程序源码下载老外写的焊接机器人程序.zip西门子PLC编程实例程序源码下载老外写的焊接机器人程序.zip西门子PLC编程实例程序源码下载老外写的焊接机器人程序.zip西门子PLC...
3、由于受prototype.js(老外写的框架,用于将一些常用的函数封装,方便操作)的影响, 现在很多人都用 $来表示一个查找对象的函数, $=function (id) { return (typeof (id)==’object’)?id:document.get
中国工程师写英文时最常犯的错误 The Most Common Habits from more than 200 English Papers written by Graduate Chinese Engineering Students 17页
老外写的程序软件,老外写的程序软件,老外写的程序软件老外写的程序软件
老外写的翻页效果 leaves老外写的翻页效果 leaves
老外写的PHP的SMTP邮件类 外带Debug模式,很好很强大
老外写的3DES不错老外写的3DES不错老外写的3DES不错
老外写的42个QT例子老外写的42个QT例子
如果是老外写的英文代码 你可以调用这个程序 吧所有的英文注释 翻译成中文的 使用的时候在AppConfig里的client_id写上你的百度翻译开发者账号AppId 如果你没有用我的CasNoTBoI1xPZTvOGiE6o685不要随便传播