知识点 词汇表 联系我们
按类别浏览
内容搜索    
当前位置:WEB开发技术知识库(www.cn-web.com) .: .Net技术 .: .Net代码库 .: 检测字符串是否为数字

检测字符串是否为数字

public static bool CheckIsNumber(string str)
{
    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(str) &&
        !objTwoDotPattern.IsMatch(str) &&
        !objTwoMinusPattern.IsMatch(str) &&
        objNumberPattern.IsMatch(str);
}

对此文章打分评级

用户评论

增加评论
此文章还没有任何评论!
网站地图 - 知识词汇 - 全文检索 - 广告服务 - 帮助中心 - 联系我们
.:www.cn-web.com
网站技术开发联盟之WEB开发技术知识库
联系人:老韩(QQ:5679551)
晋ICP备07003487号