zoukankan      html  css  js  c++  java
  • Javascript 正则表达式校验数字

    $("input[datatype=number]").blur(function () {
                         var str = $(this).val();
                         if (!isDecimal(str)) {
                             alert("请输入数字");
                         }
                     });

    function isDecimal(str) {
                    if (isInteger(str)) return true;
                    var re = /^[-]{0,1}(d+)[.]+(d+)$/;
                    if (re.test(str)) {
                        if (RegExp.$1 == 0 && RegExp.$2 == 0) return false;
                        return true;
                    } else {
                        return false;
                    }
                }
                function isInteger(str) {
                    var regu = /^[-]{0,1}[0-9]{1,}$/;
                    return regu.test(str);
                }

  • 相关阅读:
    sort排序
    js数组
    json数据格式 与 for in
    js 定时器
    鼠标滚轮事件
    cookie
    POJ 2387 Til the Cows Come Home
    POJ 1459 Power Network
    HDU 5389 Zero Escape
    HDU 5387 Clock
  • 原文地址:https://www.cnblogs.com/umlzhang/p/3607045.html
Copyright © 2011-2022 走看看