ValidateUtil.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:4k
- using System;
- using System.Text;
- namespace qminoa.Common
- {
- /// <summary>
- /// 验证字符串是否合法
- /// </summary>
- public class ValidateUtil
- {
- /// <summary>构造函数</summary>
- public ValidateUtil()
- {
- }
- /// <summary>是否空</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isBlank(string strInput)
- {
- if (strInput==null || strInput.Trim()=="")
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- /// <summary>是否数字</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isNumeric(string strInput)
- {
-
- char[] ca =strInput.ToCharArray();
- bool found=true;
- for (int i=0;i<ca.Length;i++)
- {
- if ((ca[i]<'0' || ca[i]>'9') && ca[i]!='.')
- {
-
- found=false;
- break;
-
- };
- };
- return found ;
-
- }
- /// <summary>是否日期</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isDate(string strInput)
- {
- string datestr=strInput;
- string year,month,day;
- string [] c={"/","-","."};
- string cs="";
- for (int i=0;i<c.Length;i++)
- {
- if(datestr.IndexOf(c[i])>0)
- {
- cs=c[i];
- break;
- }
-
- };
- if (cs!="" )
- {
- year=datestr.Substring(0,datestr.IndexOf(cs));
- if(year.Length!=4){return false;};
- datestr = datestr.Substring(datestr.IndexOf(cs) + 1);
- month=datestr.Substring(0,datestr.IndexOf(cs));
- if((month.Length!=2) || (Convert.ToInt16(month)>12))
- {return false;};
- datestr = datestr.Substring(datestr.IndexOf(cs) + 1);
- day=datestr;
- if((day.Length!=2) || (Convert.ToInt16(day)>31)){return false;};
- return checkDatePart(year,month,day);
- }
- else
- {
- return false;
- }
-
- }
-
- /// <summary>
- /// 检查年月日是否合法
- /// </summary>
- /// <param name="dt"></param>
- /// <param name="part"></param>
- /// <returns></returns>
- private static bool checkDatePart(string year,string month,string day)
- {
- int iyear=Convert.ToInt16(year);
- int imonth=Convert.ToInt16(month);
- int iday= Convert.ToInt16(day);
- if (iyear>2099 || iyear<1900) {return false;}
- if (imonth>12 || imonth<1) {return false;}
- if (iday>DateUtil.GetDaysOfMonth(iyear,imonth)|| iday<1) {return false;};
- return true;
-
-
- }
- /// <summary>是否Null</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isNull(object strInput)
- {
- return true ;
- }
- /// <summary>是否为Double</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isDouble(string strInput)
- {
- return true ;
- }
- /// <summary>是否为Int</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isInt(string strInput)
- {
- return true ;
- }
- /// <summary>是否为合法的电话号码</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isTel(string strInput)
- {
- //电话号码规则在Concief中配置[CurrentPhoneRule]
- return true ;
- }
- /// <summary>是否为合法的邮政编码</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isZip(string strInput)
- {
- //邮政编码规则在Concief中配置[CurrentZipRule]
- return true ;
- }
- /// <summary>是否为合法的电子邮件</summary>
- /// <param name="strInput">输入字符串</param>
- /// <returns>true/false</returns>
- public static bool isEmail(string strInput)
- {
- return true ;
- }
- }
- }