惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
T
Threatpost
G
Google Developers Blog
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
Hacker News: Ask HN
Hacker News: Ask HN
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Schneier on Security
B
Blog
V2EX - 技术
V2EX - 技术
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
Schneier on Security
Schneier on Security
F
Fortinet All Blogs
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
S
Security @ Cisco Blogs
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
Project Zero
Project Zero
I
Intezer
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
SecWiki News
SecWiki News
Martin Fowler
Martin Fowler

博客园 - 我是蚂蚁

企业销售管理现状分析与解决思路 WCF 关于自定义MessageHeader支持 如何识别真正的程序员 (转帖 来自csdn) 忙忙碌碌,早出晚归咱们到底为个啥? 2008年业务、技术学习计划 记录一下,开车以来最惨痛的教训! 针对 WCF 数据压缩开发包压缩效率的测试比较 总结,对自己对团队对项目的总结 WF 状态机 事件传参详细步骤 关于 WCF 中数据压缩的几篇文章 WF 工作流实例持久化几点说明 msdn杂志关于wcf\wwf的相关文章 - 我是蚂蚁 - 博客园 关于wf中传参的问题:如何在workflow实例钝化后重新load时传参! Pro WF Windows Workflow in NET3 -- 学习笔记 -- 状态机 -- 汽车驾驶操作示例 Pro WF Windows Workflow in NET3 -- 学习笔记 -- 状态机 (不)相信 --- 龙应台 推荐阅读 《Pro WCF Practical Microsoft SOA Implementation》 关于中小企业信息化命题的阶段性总结 WCF 学习研究 推荐blog
对正则表达式不熟悉,记录几个从别处拿来验证过的表达式,日期、数字、email、网址验证
我是蚂蚁 · 2008-06-19 · via 博客园 - 我是蚂蚁

/// <summary>
        
/// 正则表达式判断是否为数字
        
/// </summary>
        
/// <param name="strNumber"></param>
        
/// <returns></returns>

        public static bool IsNumber(string strNumber)
        
{
            
//^[-+]?[1-9]\d*\.?[0]*$
            Regex objNotNumberPattern = new Regex("[^0-9.-]");
            Regex objTwoDotPattern 
= new Regex("[0-9]*[.][0-9]*[.][0-9]*");
            Regex objTwoMinusPattern 
= new Regex("[0-9]*[-][0-9]*[-][0-9]*");
            String strValidRealPattern 
= "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
            String strValidIntegerPattern 
= "^([-]|[0-9])[0-9]*$";
            Regex objNumberPattern 
= new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");

            
return !objNotNumberPattern.IsMatch(strNumber) &&
            
!objTwoDotPattern.IsMatch(strNumber) &&
            
!objTwoMinusPattern.IsMatch(strNumber) &&
            objNumberPattern.IsMatch(strNumber);
        }


        
/// <summary>
        
///
正则表达式判断是否为日期
        
/// 验证格式:
        
/// YYYY-MM
        
/// YYYY-MM(M)-DD(M)
        
/// YYYYMMDD       
        
/// </summary>
        
/// <param name="date"></param>
        
/// <returns></returns>

        public static bool IsDate(string date)
        
{
            
//(([0-9]{4}-)([0-9]{1,2}-)[0-9]{1,2})
            Regex ymPattern = new Regex(@"^\d{4}-?(?:0[1-9]|1[0-2])$");
            Regex yyyyMMdd 
= new Regex(@"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"); //日期部分
            
            
return !ymPattern.IsMatch(date) &&
                yyyyMMdd.IsMatch(date);
        }


        
/// <summary>
        
///
正则表达式判断是否为日期
        
/// 验证格式:     
        
/// YYYY-MM(M)-DD(M) HH:MM
        
/// YYYYMMDD HH:MM
        
/// </summary>
        
/// <param name="date"></param>
        
/// <returns></returns>

        public static bool IsDateTime(string date)
        
{
            
string regex = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"//日期部分
            regex += @"(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"//时间部分
            System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex reg 
= new System.Text.RegularExpressions.Regex(regex, options);

            
return reg.IsMatch(date);
        }


        
public static bool IsEmail(string mail)
        
{
            Regex reg 
= new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

            
return reg.IsMatch(mail);
        }


        
/// <summary>
        
///
正则表达式是否为网址,验证格式:
        
/// wwww.xxx.xxx
        
/// xxx.xxx.xxx
        
/// http://www.xxx.xxx
        
/// http://xxx.xxx.xxx
        
/// </summary>
        
/// <param name="uri"></param>
        
/// <returns></returns>

        public static bool IsUri(string uri)
        
{
            Regex reg 
= new Regex(@"^(((ht|f)tp(s?))\://)?((([a-zA-Z0-9_\-]{2,}\.)+[a-zA-Z]{2,})|((?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4}))(:[a-zA-Z0-9]+)?(/[a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~]*)?$");
            
return reg.IsMatch(uri);
        }

--畅所欲言,随心而谈--
本博客文章全部原创,转载请注明出处,谢谢
紫辰友创软件公司 http://www.bornsun.net/
版权所有 jiabao.cnblogs.com 转载请联系