• 常用js验证


    1、身份证验证(带x)

    //验证身份证信息(获取出生日期和性别)
    function func_CheckSFZ(ob)
    {               
        var obj = ob.value;
        obj = obj.toUpperCase();     
        if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(obj)))      
        {    
             alert('输入的身份证号长度不对,或者号码不符合规定!\n15位号码应全为数字,18位号码末位可以为数字或X。');    
             return false;    
        } 
        var gre = /^(\d{6})(\d{2})([01]\d)([0123]\d)(\d{3})$/;
        var reg = /^(\d{6})(18|19|20)?(\d{2})([01]\d)([0123]\d)(\d{3})([0-9]|X)$/;
        var csny = document.getElementById("txt_CSRQ").value;
        var XB = document.getElementById("sel_XB").value;
        if(obj.value != "")
        {
            if(obj.length == 15 || obj.length == 18)
            {
                
                     if(obj.length == 15)
                     {
                         if(gre.test(obj))
                         {
                             var year = obj.charAt(6)+obj.charAt(7);
                             if(parseInt(year) < 10)
                             {
                                 year = "20"+ year;
                             }
                             else
                             {
                                 year = "19"+ year;
                             }                        
                             var month = obj.substring(8,10);
                             var day = obj.substring(10,12);
                             csny = year+"-"+month+"-"+day; 
                            if(parseInt(obj.charAt(14)/2)*2 != obj.charAt(14))
                            XB ="男";
                            else
                            XB = "女";   
                        }
                        else       
                        {
                           alert("提示:身份证格式不正确!");
                           return false;   
                        }               
                     }
                     else if(obj.length == 18)
                     {
                         if(reg.test(obj))
                         {
                             var year = obj.substring(6,10);
                             var month = obj.substring(10,12);
                             var day = obj.substring(12,14);                      
                             csny = year+"-"+month+"-"+day;                        
                              if(parseInt(obj.charAt(16)/2)*2 != obj.charAt(16))
                                XB ="男";
                                else
                                XB = "女";
                         }
                         else
                         {
                            alert("提示:身份证格式不正确!");
                            return false;   
                         }
                     } 
                     document.getElementById("txt_CSRQ").value = csny;   
                     document.getElementById("sel_XB").value = XB;           
                
            }
            else
            {
                alert("提示:身份证为15位或者18位!");
                return false;   
            }
        }
        return true;   
    }

    2、验证金额:

    /^-?((\d{1,3}(,\d{3})*?)|\d+)(\.\d{1,2})?$/

  • 相关阅读:
    js里面的 InttoStr 和 StrtoInt
    预编译知识 (转载记录)
    C语言操作内存
    C语言操作文件
    C语言
    如何调试shell脚本
    设计模式-装饰者模式
    自己动手制作一个模版解析
    设计模式-单例模式
    http中关于缓存的那些header信息
  • 原文地址:https://www.cnblogs.com/shinggang/p/1999538.html
Copyright © 2020-2023  润新知