jQuery Validate 驗證,校驗規(guī)則寫在控件中的具體實例
將校驗規(guī)則寫到控件中
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/jquery.validate.js" type="text/javascript"></script>
<script src="./js/jquery.metadata.js" type="text/javascript"></script>
$().ready(function() {
$("#signupForm").validate();
});
<form id="signupForm" method="get" action="">
<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" class="required" />
</p>
<p>
<label for="email">E-Mail</label>
<input id="email" name="email" class="required email" />
</p>
<p>
<label for="password">Password</label>
<input id="password" name="password" type="password" class="{required:true,minlength:5}" />
</p>
<p>
<label for="confirm_password">確認(rèn)密碼</label>
<input id="confirm_password" name="confirm_password" type="password" class="{required:true,minlength:5,equalTo:'#password'}" />
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</form>
Tips:
使用class="{}"的方式,必須引入包:jquery.metadata.js
可以使用如下的方法,修改提示內(nèi)容:
class="{required:true,minlength:5,messages:{required:'請輸入內(nèi)容'}}"
在使用equalTo關(guān)鍵字時,后面的內(nèi)容必須加上引號,如下代碼:
class="{required:true,minlength:5,equalTo:'#password'}"
- ASP.NET jQuery 實例16 通過控件CustomValidator驗證RadioButtonList
- ASP.NET jQuery 實例15 通過控件CustomValidator驗證CheckBoxList
- 使用jQuery.Validate進(jìn)行客戶端驗證(初級篇) 不使用微軟驗證控件的理由
- 基于jquery實現(xiàn)的服務(wù)器驗證控件的啟用和禁用代碼
- 教你用AngularJS框架一行JS代碼實現(xiàn)控件驗證效果
- js控制.net驗證控件是否可用。
- 驗證控件與Button的OnClientClick事件詳細(xì)解析
- fileupload控件 文件類型客戶端驗證實現(xiàn)代碼
- asp.net MaxLengthValidator 最大長度驗證控件代碼
- jQuery密碼強(qiáng)度驗證控件使用詳解
相關(guān)文章
制作高質(zhì)量的JQuery Plugin 插件的方法
最近jquery非常流行,想個性化定制一些功能,就可以將代碼寫成插件的形式,方便使用與修改。2010-04-04

