標籤:提高 密碼 conf 客戶 date 並且 for 電子 required
jQuery Validate 是功能豐富的正則驗證外掛程式,為用戶端提供了強大的驗證功能,同時提供了大量的正則選項,滿足應用程式各種需求。該外掛程式捆綁了一整套有用的驗證方法,同時包括URL驗證和電子郵件驗證,為用戶端帶來更加便捷的使用者體驗。
通過執行個體來說明一下,更易於理解。
1 //定義驗證規則 2 rules:{ 3 userName: {required: true,rangelength:[2,10]}, //true表示必填 最少2個最多10個限制字元 4 email: { required: true, email: true }, 5 password: { required: true, minlength: 6 }, //最小6個字元 6 confirm_password: { 7 required: true, 8 minlength: 5, 9 equalTo: "#password" },//判斷密碼是否一致10 age:{required: true,range:[15,40]}//最小15最大40內數值11 }
定義完正則規則並且提示資訊,提高使用者體驗。
1 //自訂提示訊息 2 messages:{ 3 userName: { 4 required: "請輸入使用者名稱", 5 rangelength: "使用者名稱的長度在2和10之間" }, 6 email: { 7 required: "請輸入Email地址", 8 email: "請輸入正確的email地址" }, 9 password: {10 required: "請輸入密碼",11 minlength: jQuery.format("密碼不能小於{0}個字元") },12 confirm_password: {13 required: "請輸入確認密碼",14 minlength: "確認密碼不能小於6個字元", 15 equalTo: "兩次輸入密碼不一致" },16 age:{17 required: "請輸入年齡",18 range:"年齡在15歲和40歲之間"19 }20 }
瞭解jQuery Validate.JS後不用再為正則驗證頭疼