常用的正则表达式验证类

搜集的一些常用的正则表达式验证类:

None.gif using  System; 
None.gif
using  System.Text.RegularExpressions; 
None.gif 
None.gif
namespace  CommonTools 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//**//**//// <summary> 
InBlock.gif    
/// RegexLib 的摘要说明。 
ExpandedSubBlockEnd.gif    
/// </summary> 

InBlock.gif    public class RegexLib 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif             
InBlock.gif            
//验证Email地址 
InBlock.gif
            public static bool IsValidEmail(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
// Return true if strIn is in valid e-mail format. 
InBlock.gif
                return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。 
InBlock.gif
            public static string MDYToDMY(String input)  
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.Replace(input,"\\b(?\\d{1,2})/(?\\d{1,2})/(?\\d{2,4})\\b","${day}-${month}-${year}"); 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证是否为小数 
InBlock.gif
            public static bool IsValidDecimal(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"[0].\d{1,2}|[1]");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证是否为电话号码 
InBlock.gif
            public static bool IsValidTel(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"(\d+-)?(\d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8})(-\d+)?");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证年月日 
InBlock.gif
            public static bool IsValidDate(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"^2\d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]\d|3[0-1])(?:0?[1-9]|1\d|2[0-3]):(?:0?[1-9]|[1-5]\d):(?:0?[1-9]|[1-5]\d)$");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证后缀名 
InBlock.gif
            public static bool IsValidPostfix(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"\.(?i:gif|jpg)$");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证字符是否再4至12之间 
InBlock.gif
            public static bool IsValidByte(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"^[a-z]{4,12}$");  
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
//验证IP 
InBlock.gif
            public static bool IsValidIp(string strIn) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
return Regex.IsMatch(strIn,@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");  
ExpandedSubBlockEnd.gif            }
             
InBlock.gif 
ExpandedSubBlockEnd.gif    }
 
ExpandedBlockEnd.gif}
 
None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值