字符串判断公共方法

ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
InBlock.gif       
/// 是否是数字型
InBlock.gif       
/// </summary>
InBlock.gif       
/// <param name="value"></param>
ExpandedBlockEnd.gif       
/// <returns></returns>

None.gif         public static bool IsNumeric( string value)
ExpandedBlockStart.gifContractedBlock.gif       
... {
InBlock.gif           
return Regex.IsMatch(value, @"^[+-]?d*[.]?d*$");
ExpandedBlockEnd.gif        }

None.gif
ExpandedBlockStart.gifContractedBlock.gif       
/**/ /// <summary>
InBlock.gif       
/// 是否是整数
InBlock.gif       
/// </summary>
InBlock.gif       
/// <param name="value"></param>
ExpandedBlockEnd.gif       
/// <returns></returns>

None.gif         public static bool IsInt( string value)
ExpandedBlockStart.gifContractedBlock.gif       
... {
InBlock.gif           
return Regex.IsMatch(value, @"^[+-]?d*$");
ExpandedBlockEnd.gif        }

None.gif
ExpandedBlockStart.gifContractedBlock.gif       
/**/ /// <summary>
InBlock.gif       
/// 是否是无符号数字
InBlock.gif       
/// </summary>
InBlock.gif       
/// <param name="value"></param>
ExpandedBlockEnd.gif       
/// <returns></returns>

None.gif         public static bool IsUnsign( string value)
ExpandedBlockStart.gifContractedBlock.gif       
... {
InBlock.gif           
return Regex.IsMatch(value, @"^d*[.]?d*$");
ExpandedBlockEnd.gif        }

ExpandedBlockStart.gifContractedBlock.gif       
/**/ /// <summary>
InBlock.gif       
/// 是否是日期型
InBlock.gif       
/// 支持的格式包括("1980-06-06"和"1980/06/06")
InBlock.gif       
/// </summary>
InBlock.gif       
/// <param name="dateStr"></param>
ExpandedBlockEnd.gif       
/// <returns></returns>

None.gif         public static bool   IsDate( string dateStr)
ExpandedBlockStart.gifContractedBlock.gif       
... {
InBlock.gif
InBlock.gif           
string datePat =@"^(d{4})(/|-)(d{1,2})(/|-)(d{1,2})$";
InBlock.gif           
bool IsMatch=Regex.IsMatch(dateStr,datePat);
InBlock.gif           
//日期格式不正确,正确格式:1980-06-06
InBlock.gif
            if(!IsMatch)
InBlock.gif               
return false;
InBlock.gif           
string[] dates=dateStr.Split('/','-');           
InBlock.gif           
if(dates==null || dates.Length<3)
InBlock.gif               
return false;
InBlock.gif
InBlock.gif           
int year =int.Parse(dates[0]);
InBlock.gif           
int month =int.Parse(dates[1]);
InBlock.gif           
int day =int.Parse(dates[2]);
InBlock.gif
InBlock.gif           
if (month < 1 || month > 12)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{
InBlock.gif               
//"月份必须是1月-12月之间";
InBlock.gif
                return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif           
if (day < 1 || day > 31)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{
InBlock.gif               
//"日必须是1-31日之间";
InBlock.gif
                return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif           
if ((month==4 || month==6 || month==9 || month==11) && day==31)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{
InBlock.gif               
//month doesn't have 31 days!"
InBlock.gif
                    return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif           
if (month == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{ // check for february 29th
InBlock.gif
                bool isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
InBlock.gif               
if (day > 29 || (day==29 && !isleap))
ExpandedSubBlockStart.gifContractedSubBlock.gif               
...{
InBlock.gif                   
// year + " 年 2 月没有 " + day + " 日"
InBlock.gif
                    return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif           
return true; // date is valid
ExpandedBlockEnd.gif
        }

None.gif       
#endregion

转载于:https://www.cnblogs.com/pbwf/archive/2007/05/26/761100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值