JQuery.validate的一些規則

最近需要用到一些前端的驗證,在這邊紀錄一下自己所用的規則

身分證驗證
jQuery.validator.addMethod("ROC_Citizen_ID",
            function(citizenid, element) {

                citizenid = citizenid.replace(/\s+/g, "");

                return(
                    this.optional(element) || /^[A-Z]{1}[1-2]{1}[0-9]{8}$/.test(citizenid));

        }, "不合理的身分證字號");
台灣地區手機驗證(XXXX-XXXXXX)
jQuery.validator.addMethod("ROC_Celphone",
            function(cellphone, element) {

                cellphone = cellphone.replace(/\s+/g, "");

                return(
                    this.optional(element) || /[0][1-9]{3}\-[0-9]{6}/.test(cellphone));

        }, "請輸入XXXX-XXXXXX");
台灣地區市話驗證(XX-XXXXXXXX)
jQuery.validator.addMethod("ROC_Telphone",
            function(cellphone, element) {

                cellphone = cellphone.replace(/\s+/g, "");

                return(
                    this.optional(element) || /[0-9]{2}\-[0-9]{7}/.test(cellphone));

        }, "請輸入XX-XXXXXXXX");

Comments

comments powered by Disqus