<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>01_validatebox.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../themes/default/easyui.css" type="text/css"></link> <link rel="stylesheet" href="../themes/icon.css" type="text/css"></link> <script type="text/javascript" src="../js/jquery.min.js"></script> <script type="text/javascript" src="../js/jquery.easyui.min.js"></script> <script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script> </head> <body> <div style="margin:200px"></div> 姓名:<input id="nameID"/><p/> <script type="text/javascript"> $("#nameID").validatebox({ required : true, validType : [‘length[1,6]‘,‘zhongwen‘] }); </script> <script type="text/javascript"> //自定义规则:zhongwen $.extend($.fn.validatebox.defaults.rules, { //zhongwen规则名 zhongwen: { //validator验证体 //value表示用户在文本框中输入的内容 validator: function(value){ //如果符合中文规则 if(/^[\u3220-\uFA29]*$/.test(value)){ return true; } }, //如果不符合中文规则,以下就是提示信息 message: ‘姓名必须为中文‘ } }); </script> 邮箱:<input id="emailID"/><p/> <script type="text/javascript"> $("#emailID").validatebox({ required : true, validType : [‘length[1,30]‘,‘email‘] }); </script> 密码:<input id="passwordID"/><p/> <script type="text/javascript"> $("#passwordID").validatebox({ required : true, validType : [‘length[6,6]‘,‘english‘] }); </script> <script type="text/javascript"> $.extend($.fn.validatebox.defaults.rules, { english: { validator: function(value){ if(/^[a-zA-Z]*$/.test(value)){ return true; } }, message: ‘密码必须为英文‘ } }); </script> </body> </html>
原文地址:https://www.cnblogs.com/loaderman/p/10062540.html
时间: 2024-10-18 07:41:37