-
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>
-
相关阅读:
OpenStreetMap、googleMap等经纬度和行列号之间相互转化(python,JavaScript,php,Java,C#等)
利用whoosh对mongoDB的中文文档建立全文检索
js前端读写文件的方法(json、excel)
部分网站公开数据的汇总(1)
部分网站公开数据的汇总(2)
Buuctf-misc-[BJDCTF 2nd]最简单的misc-y1ng
Buuctf-web-[SUCTF 2019]CheckIn
Buuctf-web-[ACTF2020 新生赛]Upload
Buuctf-web-[ACTF2020 新生赛]BackupFile
Buuctf-web-[极客大挑战 2019]Upload
-
原文地址:https://www.cnblogs.com/BluceLee/p/4092241.html
Copyright © 2020-2023
润新知