-
jQuery.Validate自定义规程的使用案例
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>jquery.validate自定义规则的使用方法</title>
- <script src="jquery.js" type="text/javascript"></script>
- <script src="jquery.validate.min.js" type="text/javascript"></script>
- <script type="text/javascript" language="javascript">
-
- $.validator.addMethod("buga", function(value) {
- return value == "buga";
- }, 'Please enter "buga"!');
- $.validator.addMethod("chinese", function(value, element) {
- var chinese = /^[u4e00-u9fa5]+$/;
- return (chinese.test(value)) || this.optional(element);
- }, "只能输入中文");
- jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {
- var length = value.length;
- for (var i = 0; i < value.length; i++) {
- if (value.charCodeAt(i) > 127) {
- length++;
- }
- }
- return this.optional(element) || (length >= param[0] && length <= param[1]);
- }, $.validator.format("请确保输入的值在{0}-{1}个字节之间(一个中文字算2个字节)"));
-
- $(function(){
-
- $("#form1").validate({
- rules: {
- username:{
- required:true,
- chinese:true,
- byteRangeLength:[1,2]
- }
-
-
-
- }
- });
-
- });
- </script>
- </head>
-
- <body>
-
- <form id="form1" name="form1" method="post" action="">
- <p>
- <label for="username">用户名:</label>
- <input type="text" name="username" id="username"/>
- </p>
- <p>
- <input type="submit" name="button" id="button" value="提交" />
- </p>
- </form>
-
- </body>
- </html>
-
相关阅读:
第三篇——第二部分——第三文 配置SQL Server镜像——域环境
DOS命令学习(从入门到精通)
Cocos2d-x3.0 LoadingBar
微信对接HIS——微信可查检验结果
微信iOS SDK文档总结
Azure编程笔记(4):配置Cloud Service的证书
android的ViewPager和Animation的一些使用(一)
小虾米的鳄鱼梦
Hadoop源码分析21:namenode概要
Hadoop源码分析20:datanode概要
-
原文地址:https://www.cnblogs.com/BluceLee/p/4092241.html
Copyright © 2020-2023
润新知