先去下载:https://github.com/posabsolute/jQuery-Validation-Engine
页面加载相关文件
<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css"/> <script src="../js/jquery-1.8.2.min.js" type="text/javascript"></script> <!-- 如果是中文就改成jquery.validationEngine-zh_CN.js --> <script src="../js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"> </script> <script src="../js/jquery.validationEngine.js" type="text/javascript" charset="utf-8">
添加模式:
<form action="/" method="post" name="myform" id="myform"> <table class="insert-tab"> <tbody> <tr> <th width="120px">客户账号:</th> <td> <input type="text" name="username" value="" class="validate[required]"> </td> </tr> <tr> <th>新密码:</th> <td> <input type="password" name="password" id="password" value="" class="validate[required,minSize[6]] text-input"> </td> </tr> <tr> <th>确定新密码:</th> <td> <input type="password" name="repassword" value="" class="validate[required,equals[password]] text-input" > </td> </tr> <tr> <th>邮箱:</th> <td> <input type="email" name="email" id="email" data-validation-engine="validate[required,custom[email]]"/> </td> </tr> <tr> <th></th> <td> <input class="btns btn-primary btn6 mr10" value="提交" type="submit"> <input class="btns btn6" onclick="history.go(-1)" value="返回" type="button"> </td> </tr> </tbody></table> </form>
修改模式下密码不填写就不修改可以写成
<tr> <th>密码:</th> <td><input type="password" name="password" id="password" class="validate[minSize[6]] text-input"/></td> </tr> <tr> <th>重复密码:</th> <td><input type="password" name="repassword" class="validate[condRequired[password],equals[password]] text-input"/></td> </tr>
如果要邮箱要自定义提示消息:
<input type="email" name="email" id="email" data-validation-engine="validate[required,custom[email]]" data-errormessage-value-missing="邮箱不能为空" data-errormessage-custom-error="给你一个提示: someone@nowhere.com" data-errormessage="返回错误消息。"/>
本文链接:http://www.shenmdyw.com/index.php/2016/01/04/jquery-validation/