標籤:
表單代碼:<table border="0px" style="font-size:12px"> <tr> <td colpan="3"><input type="submit" name="button" id="button" value="提交" /></td> </tr> <tr> <td align="right">身份證(Regex庫):</td> <td><input name="sfz" type="text" id="sfz" /></td> <td><div id="sfzTip" style="width:300px"></div></td> <!--必須注意這裡提示驗證資訊中的div的id值,跟要驗證控制項中的id值多了一個Tip,下面的都是這樣。必須多的是Tip,也必須要多。--> </tr> <tr> <td align="right">身份證(外部函數):</td> <td><input type="text" id="sfz1" style="width:120px" /></td> <td><div id="sfz1Tip" style="width:300px"></div></td> </tr> <tr> <td align="right">整數:</td> <td><input type="text" id="zs" style="width:120px" /></td> <td><div id="zsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">正整數:</td> <td><input type="text" id="zzs" style="width:120px" /></td> <td><div id="zzsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">負整數:</td> <td><input type="text" id="fzs" style="width:120px" /></td> <td><div id="fzsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">數字:</td> <td><input type="text" id="sz" style="width:120px" /></td> <td><div id="szTip" style="width:300px"></div></td> </tr> <tr> <td align="right">正數(正整數 + 0):</td> <td><input type="text" id="zs1" style="width:120px" /></td> <td><div id="zs1Tip" style="width:300px"></div></td> </tr> <tr> <td align="right">負數(負整數 + 0):</td> <td><input type="text" id="fs" style="width:120px" /></td> <td><div id="fsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">浮點數:</td> <td><input type="text" id="fds" style="width:120px" /></td> <td><div id="fdsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">正浮點數:</td> <td><input type="text" id="zfds" style="width:120px" /></td> <td><div id="zfdsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">負浮點數:</td> <td><input type="text" id="ffds" style="width:120px" /></td> <td><div id="ffdsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">非負浮點數(正浮點數 + 0):</td> <td><input type="text" id="fffds" style="width:120px" /></td> <td><div id="fffdsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">非正浮點數(負浮點數 + 0):</td> <td><input type="text" id="fzfds" style="width:120px" /></td> <td><div id="fzfdsTip" style="width:300px"></div></td> </tr> <tr> <td align="right">顏色:</td> <td><input type="text" id="ys" style="width:120px" /></td> <td><div id="ysTip" style="width:300px"></div></td> </tr> <tr> <td align="right">你的EMAIL:</td> <td><input type="text" id="email" style="width:120px" /></td> <td><div id="emailTip" style="width:300px"></div></td> </tr> <tr> <td align="right">手機:</td> <td><input type="text" id="sj" style="width:120px" /></td> <td><div id="sjTip" style="width:300px"></div></td> </tr> <tr> <td align="right">郵編:</td> <td><input type="text" id="yb" style="width:120px" /></td> <td><div id="ybTip" style="width:300px"></div></td> </tr> <tr> <td align="right">非空:</td> <td><input type="text" id="fk" style="width:120px" /></td> <td><div id="fkTip" style="width:300px"></div></td> </tr> <tr> <td align="right">圖片:</td> <td><input type="text" id="tp" style="width:120px" /></td> <td><div id="tpTip" style="width:300px"></div></td> </tr> <tr> <td align="right">壓縮檔:</td> <td><input type="text" id="rar" style="width:120px" /></td> <td><div id="rarTip" style="width:300px"></div></td> </tr> <tr> <td align="right">ip4:</td> <td><input type="text" id="ip4" style="width:120px" /></td> <td><div id="ip4Tip" style="width:300px"></div></td> </tr> <tr> <td align="right">QQ號碼:</td> <td><input type="text" id="qq" style="width:120px" /></td> <td><div id="qqTip" style="width:300px"></div></td> </tr> <tr> <td align="right">國內電話:</td> <td><input type="text" id="dh" style="width:120px" /></td> <td><div id="dhTip" style="width:300px"></div></td> </tr> <tr> <td align="right">使用者名稱:</td> <td><input type="text" id="yhm" style="width:120px" /></td> <td><div id="yhmTip" style="width:300px"></div></td> </tr> <tr> <td align="right">字母:</td> <td><input type="text" id="zm" style="width:120px" /></td> <td><div id="zmTip" style="width:300px"></div></td> </tr> <tr> <td align="right">大寫字母:</td> <td><input type="text" id="dxzm" style="width:120px" /></td> <td><div id="dxzmTip" style="width:300px"></div></td> </tr> <tr> <td align="right">小寫字母:</td> <td><input type="text" id="xxzm" style="width:120px" /></td> <td><div id="xxzmTip" style="width:300px"></div></td> </tr> <tr> <td align="right">身份證:</td> <td><input type="text" id="sfz" style="width:120px" /></td> <td><div id="sfzTip" style="width:300px"></div></td> </tr> </table>script 中代碼<script type="text/javascript"> $(document).ready(function () { $.formValidator.initConfig({ formID: "form1", onError: function () { alert("校正沒有通過,具體錯誤請看錯誤提示") } }); $("#sfz").formValidator({ onShow: "請輸入15或18位的身份證", onfocus: "輸入15或18位的身份證", onCorrect: "輸入正確" }).regexValidator({ regExp: "idcard", dataType: "enum", onError: "你輸入的身份證格式不正確" }); ; $("#sfz1").formValidator({ onShow: "請輸入15或18位的身份證", onfocus: "輸入15或18位的身份證", onCorrect: "輸入正確" }).functionValidator({ fun: isCardID }); $("#zs").formValidator({ onShow: "請輸入整數", onCorrect: "謝謝你的合作,你的整數正確" }).regexValidator({ regExp: "intege", dataType: "enum", onError: "整數格式不正確" }); $("#zzs").formValidator({ onShow: "請輸入正整數", onCorrect: "謝謝你的合作,你的正整數正確" }).regexValidator({ regExp: "intege1", dataType: "enum", onError: "正整數格式不正確" }); $("#fzs").formValidator({ onShow: "請輸入負整數", onCorrect: "謝謝你的合作,你的負整數正確" }).regexValidator({ regExp: "intege2", dataType: "enum", onError: "負整數格式不正確" }); $("#sz").formValidator({ onShow: "請輸入數字", onCorrect: "謝謝你的合作,你的數字正確" }).regexValidator({ regExp: "num", dataType: "enum", onError: "數字格式不正確" }); $("#zs1").formValidator({ onShow: "請輸入正數", onCorrect: "謝謝你的合作,你的正數正確" }).regexValidator({ regExp: "num1", dataType: "enum", onError: "正數格式不正確" }); $("#fs").formValidator({ onShow: "請輸入負數", onCorrect: "謝謝你的合作,你的負數正確" }).regexValidator({ regExp: "num2", dataType: "enum", onError: "負數格式不正確" }); $("#sj").formValidator({ onShow: "請輸入你的手機號碼", onfocus: "必須是13或15打頭哦", onCorrect: "謝謝你的合作,你的手機號碼正確" }).regexValidator({ regExp: "mobile", dataType: "enum", onError: "手機號碼格式不正確" }); //$("#").formValidator({onShow:"",onfocus:"請輸入",onCorrect:"謝謝你的合作,你的正確"}).regexValidator({regExp:"",dataType:"enum",onError:"格式不正確"}); $("#email").formValidator({ onShow: "請輸入你的email", onfocus: "請注意你輸入的email格式,例如:[email protected]", onCorrect: "謝謝你的合作,你的email正確" }).regexValidator({ regExp: "email", dataType: "enum", onError: "email格式不正確" }); $("#fds").formValidator({ onShow: "請輸入浮點數", onCorrect: "謝謝你的合作,你的浮點數正確" }).regexValidator({ regExp: "decmal", dataType: "enum", onError: "浮點數格式不正確" }); $("#zfds").formValidator({ onShow: "請輸入正浮點數", onCorrect: "謝謝你的合作,你的正浮點數正確" }).regexValidator({ regExp: "decmal1", dataType: "enum", onError: "正浮點數格式不正確" }); $("#ffds").formValidator({ onShow: "請輸入負浮點數", onCorrect: "謝謝你的合作,你的負浮點數正確" }).regexValidator({ regExp: "decmal2", dataType: "enum", onError: "負浮點數格式不正確" }); $("#fffds").formValidator({ onShow: "請輸入非負浮點數", onCorrect: "謝謝你的合作,你的非負浮點數正確" }).regexValidator({ regExp: "decmal4", dataType: "enum", onError: "非負浮點數格式不正確" }); $("#fzfds").formValidator({ onShow: "請輸入非正浮點數", onCorrect: "謝謝你的合作,你的非正浮點數正確" }).regexValidator({ regExp: "decmal5", dataType: "enum", onError: "非正浮點數格式不正確" }); $("#ys").formValidator({ onShow: "請輸入16進位顏色", onCorrect: "謝謝你的合作,你的16進位顏色正確" }).regexValidator({ regExp: "color", dataType: "enum", onError: "16進位顏色格式不正確" }); $("#yb").formValidator({ onShow: "請輸入郵編", onfocus: "6位元字組成的哦", onCorrect: "謝謝你的合作,你的郵編正確" }).regexValidator({ regExp: "zipcode", dataType: "enum", onError: "郵編格式不正確" }); $("#ip4").formValidator({ onShow: "請輸入ip4", onfocus: "例如:172.16.201.18", onCorrect: "謝謝你的合作,你的ip4正確" }).regexValidator({ regExp: "ip4", dataType: "enum", onError: "ip4格式不正確" }); $("#fk").formValidator({ onShow: "請輸入非Null 字元", onCorrect: "謝謝你的合作,你的非Null 字元正確" }).regexValidator({ regExp: "notempty", dataType: "enum", onError: "非Null 字元格式不正確" }); $("#tp").formValidator({ onShow: "請輸入圖片名", onCorrect: "謝謝你的合作,你的圖片名正確" }).regexValidator({ regExp: "picture", dataType: "enum", onError: "圖片名格式不正確" }); $("#rar").formValidator({ onShow: "請輸入壓縮檔名", onCorrect: "謝謝你的合作,你的壓縮檔名正確" }).regexValidator({ regExp: "rar", dataType: "enum", onError: "壓縮檔名格式不正確" }); $("#qq").formValidator({ onShow: "請輸入QQ號碼", onCorrect: "謝謝你的合作,你的QQ號碼正確" }).regexValidator({ regExp: "qq", dataType: "enum", onError: "QQ號碼格式不正確" }); $("#dh").formValidator({ onShow: "請輸入國內電話", onfocus: "例如:0577-88888888或省略區號88888888", onCorrect: "謝謝你的合作,你的國內電話正確" }).regexValidator({ regExp: "tel", dataType: "enum", onError: "國內電話格式不正確" }); $("#yhm").formValidator({ onShow: "請輸入使用者名稱", onCorrect: "謝謝你的合作,你的使用者名稱正確" }).regexValidator({ regExp: "username", dataType: "enum", onError: "使用者名稱格式不正確" }); $("#zm").formValidator({ onShow: "請輸入字母", onCorrect: "謝謝你的合作,你的字母正確" }).regexValidator({ regExp: "letter", dataType: "enum", onError: "字母格式不正確" }); $("#dxzm").formValidator({ onShow: "請輸入大寫字母", onCorrect: "謝謝你的合作,你的大寫字母正確" }).regexValidator({ regExp: "letter_u", dataType: "enum", onError: "大寫字母格式不正確" }); $("#xxzm").formValidator({ onShow: "請輸入小寫字母", onCorrect: "謝謝你的合作,你的小寫字母正確" }).regexValidator({ regExp: "letter_l", dataType: "enum", onError: "小寫字母格式不正確" }); $("#sfz").formValidator({ onShow: "請輸入身份證", onCorrect: "謝謝你的合作,你的身份證正確" }).regexValidator({ regExp: "idcard", dataType: "enum", onError: "身份證格式不正確" }); });</script>
jquery 表單驗證