zoukankan      html  css  js  c++  java
  • 项目中用到的正则

    一、小数

    str.replace(/[^d.]+/g,'').replace('.','$#$').replace(/./g,'').replace('$#$','.').replace(/^./g,'')

    将所有不是数字和小数点的置空,将第一个小数点变为$#$,将所有小数点置空,将$#$变为小数点,将首位小数点置空

    二、只能是字母数字和汉字

    str.replace(/[^a-zA-0-9u4E00-u9FA5]/g,'')

    三、只能是数字

    str.value.replace(/D/g,'')

    四、日期格式

    <input type='text' onkeyup='checkDate(this.value,jQuery(this))' onblur='blurdate(this.value,jQuery(this))' >
    
    function checkDate(date,a){
        if(date.length==10){
            var reg = /^(d{1,4})(-)(d{1,2})2(d{1,2})$/;
            var r = date.match(reg);
            if(r==null){
                swal({
                    title: "您输入的日期格式不正确!",
                    timer: 1300,
                    type:"warning",
                    showConfirmButton: false
                });
                a.val("")
            }else{
                var d = new Date(r[1], r[3] - 1, r[4]);
                var c=(d.getFullYear() == r[1] && (d.getMonth() + 1) == re[3] && d.getDate() == r[4]);
                if(!c){
                    swal({
                        title: "请输入正确的日期!",
                        timer: 1300,
                        type:"warning",
                        showConfirmButton: false
                    });
                    a.val("");
                }
            }
        }
    }
    function blurdate(date,a){
        if(date!=""){
           if(date.length<10){
                swal({
                        title: "您输入的日期格式不正确!",
                        timer: 1300,
                        type:"warning",
                        showConfirmButton: false
                    });
                a.val("")
                a.parent().parent().find("input[type=hidden]").val("");
            }
        }
    }
    --by 驻北静望
  • 相关阅读:
    jQuery UI DatePicker用法和中文设置
    jQuery的ajax方法
    jQuery遍历复杂的JSON数据
    JavaScript面向对象的写法
    jpa
    日志
    全局异常的处理!
    oracle表空间
    plsql的连接配置
    pLsql使用
  • 原文地址:https://www.cnblogs.com/web520/p/8023925.html
Copyright © 2011-2022 走看看