金鹏

|| 叶落知秋,见微知著。|| 不出户,知天下﹔不窥牖,见天道。其出弥远,其知弥少。是以圣人不行而知,不见而明,不为而成。

博客园 首页 新随笔 联系 订阅 管理
public sealed class ValidateForm
    
{
        
//判断字符是否为数字#region //判断字符是否为数字
        ///<summary>
        
/// 判断字符是否为数字
        
/// </summary>
        
/// <param name="_strNum">传入的字符串</param>
        
/// <returns>boolean</returns>

        public static bool isNumeric(string _strNum)
        
{
            
if (_strNum == null || _strNum == string.Empty)
                
return false;
            
for (int i = 0; i < _strNum.Length; i++)
            
{
                
if (!Char.IsNumber(_strNum, i))
                    
return false;
            }

            
return true;
        }

        
#endregion

        
///<summary>
        
/// 验证Email地址 
        
/// </summary>
        
/// <param name="strIn"></param>
        
/// <returns></returns>

        public static bool IsValidEmail(string strIn)
        
{
            
// Return true if strIn is in valid e-mail format. 
            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})(]?)$");
        }


        
///<summary>
        
/// dd-mm-yy 的日期形式代替 mm/dd/yy 的日期形式。
        
/// </summary>
        
/// <param name="input"></param>
        
/// <returns></returns> 

        public static string MDYToDMY(String input)
        
{
            
return Regex.Replace(input, "(?d{1,2})/(?d{1,2})/(?d{2,4})""${day}-${month}-${year}");
        }


        
//验证是否为小数 
        public static bool IsValidDecimal(string strIn)
        
{
            
return Regex.IsMatch(strIn, @"[0].d{1,2}|[1]");
        }

        
//验证是否为电话号码 
        public static bool IsValidTel(string strIn)
        
{
            
return Regex.IsMatch(strIn, @"(d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?");
        }

        
//验证年月日 
        public static bool IsValidDate(string strIn)
        
{
            
return Regex.IsMatch(strIn, @"^2d{3}-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|[1-2]d|3[0-1])(?:0?[1-9]|1d|2[0-3]):(?:0?[1-9]|[1-5]d):(?:0?[1-9]|[1-5]d)$");
        }

        
//验证后缀名 
        public static bool IsValidPostfix(string strIn)
        
{
            
return Regex.IsMatch(strIn, @".(?i:gif|jpg)$");
        }

        
//验证字符是否再4至12之间 
        public static bool IsValidByte(string strIn)
        
{
            
return Regex.IsMatch(strIn, @"^[a-z]{4,12}$");
        }

        
//验证IP 
        public static bool IsValidIp(string strIn)
        
{
            
return Regex.IsMatch(strIn, @"^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$");
        }

        
public static bool IsURL(string URL)
        
{   
          
return Regex.IsMatch(URL ,"((^http)|(^https)|(^ftp))://(w)+.(w)+");          
        }


        判断号码是联通,移动,电信中的哪个,在使用本方法前,请先验证号码的合法性
判断号码是联通,移动,电信中的哪个,在使用本方法前,请先验证号码的合法性

        验证输入的18位身份证号码是否正确
验证输入的18位身份证号码是否正确
    }
posted on 2008-01-16 12:07  金鹏  阅读(196)  评论(0编辑  收藏  举报