easyui validatebox 验证类型
required: "必選字段",
??????? remote: "請修正該字段",
??????? email: "請輸入正確格式的電子郵件",
??????? url: "請輸入合法的網址",
??????? date: "請輸入合法的日期",
??????? dateISO: "請輸入合法的日期 (ISO).",
??????? number: "請輸入合法的數字",
??????? digits: "只能輸入整數",
??????? creditcard: "請輸入合法的信用卡號",
??????? equalTo: "請再次輸入相同的值",
??????? accept: "請輸入擁有合法后綴名的字符串",
??????? maxlength: jQuery.format("請輸入一個長度最多是 {0} 的字符串"),
??????? minlength: jQuery.format("請輸入一個長度最少是 {0} 的字符串"),
??????? rangelength: jQuery.format("請輸入一個長度介于 {0} 和 {1} 之間的字符串"),
??????? range: jQuery.format("請輸入一個介于 {0} 和 {1} 之間的值"),
??????? max: jQuery.format("請輸入一個最大為 {0} 的值"),
??????? min: jQuery.format("請輸入一個最小為 {0} 的值")
data-options="required:true,validType:'length[1,3]'" ;//輸入字符長度1-3位
boolen b=$('#txt_Name').validatebox("isValid");//驗證結果
?注意日期格式驗證必須自己重寫,參考如下
?$.extend($.fn.validatebox.defaults.rules, {
??????????? idcard: {// 驗證***
??????????????? validator: function (value) {
??????????????????? return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
??????????????? },
??????????????? message: '***號碼格式不正確'
??????????? },
??????????? minLength: {
??????????????? validator: function (value, param) {
??????????????????? return value.length >= param[0];
??????????????? },
??????????????? message: '請輸入至少(2)個字符.'
??????????? },
??????????? length: { validator: function (value, param) {
??????????????? var len = $.trim(value).length;
??????????????? return len >= param[0] && len <= param[1];
??????????? },
??????????????? message: "輸入內容長度必須介于{0}和{1}之間."
??????????? },
??????????? phone: {// 驗證電話號碼
??????????????? validator: function (value) {
??????????????????? return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
??????????????? },
??????????????? message: '格式不正確,請使用下面格式:020-88888888'
??????????? },
??????????? mobile: {// 驗證手機號碼
??????????????? validator: function (value) {
??????????????????? return /^(13|15|18)\d{9}$/i.test(value);
??????????????? },
??????????????? message: '手機號碼格式不正確'
??????????? },
??????????? intOrFloat: {// 驗證整數或小數
??????????????? validator: function (value) {
??????????????????? return /^\d+(\.\d+)?$/i.test(value);
??????????????? },
??????????????? message: '請輸入數字,并確保格式正確'
??????????? },
??????????? currency: {// 驗證貨幣
??????????????? validator: function (value) {
??????????????????? return /^\d+(\.\d+)?$/i.test(value);
??????????????? },
??????????????? message: '貨幣格式不正確'
??????????? },
??????????? qq: {// 驗證QQ,從10000開始
??????????????? validator: function (value) {
??????????????????? return /^[1-9]\d{4,9}$/i.test(value);
??????????????? },
??????????????? message: 'QQ號碼格式不正確'
??????????? },
??????????? integer: {// 驗證整數?可正負數
??????????????? validator: function (value) {
??????????????????? //return /^[+]?[1-9]+\d*$/i.test(value);
??????????????????? return /^([+]?[0-9])|([-]?[0-9])+\d*$/i.test(value);
??????????????? },
??????????????? message: '請輸入整數'
??????????? },
??????????? age: {// 驗證年齡
??????????????? validator: function (value) {
??????????????????? return /^(?:[1-9][0-9]?|1[01][0-9]|120)$/i.test(value);
??????????????? },
??????????????? message: '年齡必須是0到120之間的整數'
??????????? },
??????????? chinese: {// 驗證中文
??????????????? validator: function (value) {
??????????????????? return /^[\Α-\¥]+$/i.test(value);
??????????????? },
??????????????? message: '請輸入中文'
??????????? },
??????????? english: {// 驗證英語
??????????????? validator: function (value) {
??????????????????? return /^[A-Za-z]+$/i.test(value);
??????????????? },
??????????????? message: '請輸入英文'
??????????? },
??????????? unnormal: {// 驗證是否包含空格和非法字符
??????????????? validator: function (value) {
??????????????????? return /.+/i.test(value);
??????????????? },
??????????????? message: '輸入值不能為空和包含其他非法字符'
??????????? },
??????????? username: {// 驗證用戶名
??????????????? validator: function (value) {
??????????????????? return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value);
??????????????? },
??????????????? message: '用戶名不合法(字母開頭,允許6-16字節,允許字母數字下劃線)'
??????????? },
??????????? faxno: {// 驗證傳真
??????????????? validator: function (value) {
??????????????????? //??????????? return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value);
??????????????????? return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
??????????????? },
??????????????? message: '傳真號碼不正確'
??????????? },
??????????? zip: {// 驗證郵政編碼
??????????????? validator: function (value) {
??????????????????? return /^[1-9]\d{5}$/i.test(value);
??????????????? },
??????????????? message: '郵政編碼格式不正確'
??????????? },
??????????? ip: {// 驗證IP地址
??????????????? validator: function (value) {
??????????????????? return /d+.d+.d+.d+/i.test(value);
??????????????? },
??????????????? message: 'IP地址格式不正確'
??????????? },
??????????? name: {// 驗證姓名,可以是中文或英文
??????????????? validator: function (value) {
??????????????????? return /^[\Α-\¥]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value);
??????????????? },
??????????????? message: '請輸入姓名'
??????????? },
??????????? date: {// 驗證姓名,可以是中文或英文
??????????????? validator: function (value) {
??????????????????? //格式yyyy-MM-dd或yyyy-M-d
??????????????????? return /^(?:(?!0000)[0-9]{4}([-]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-]?)0?2\2(?:29))$/i.test(value);
??????????????? },
??????????????? message: '清輸入合適的日期格式'
??????????? },
??????????? msn: {
??????????????? validator: function (value) {
??????????????????? return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value);
??????????????? },
??????????????? message: '請輸入有效的msn賬號(例:abc@hotnail(msn/live).com)'
??????????? },
??????????? same: {
??????????????? validator: function (value, param) {
??????????????????? if ($("#" + param[0]).val() != "" && value != "") {
??????????????????????? return $("#" + param[0]).val() == value;
??????????????????? } else {
??????????????????????? return true;
??????????????????? }
??????????????? },
??????????????? message: '兩次輸入的密碼不一致!'
??????????? }
??????? });
//驗證實例
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
??? <script src="easyui1.2.4/jquery-1.6.min.js" type="text/javascript"></script>
??? <script src="easyui1.2.4/jquery.easyui.min.js" type="text/javascript"></script>
??? <!--自定義驗證-->
??? <script src="easyui1.2.4/validator.js" type="text/javascript"></script>
??? <link href="easyui1.2.4/themes/default/easyui.css" rel="stylesheet" type="text/css" />
??? <script>
??????? $(function () {
???????????
??????????? //設置text須要驗證
??????????? $(""input[type=text]"").validatebox();
??????? })
???
??? </script>
</head>
<body>
??? 郵箱驗證:<input type="text" validtype="email" required="true" missingMessage="不克不及為空" invalidMessage="郵箱格局不正確" /><br />
??? 網址驗證:<input type="text" validtype="url" invalidMessage="url格局不正確[http://www.example.com]" /><br />
??? 長度驗證:<input type="text" validtype="length[8,20]" invalidMessage="有效長度8-20" /><br />
??? 手機驗證:<input type="text" validtype="mobile"? /><br />
??? 郵編驗證:<input type="text" validtype="zipcode" /><br />
??? 賬號驗證:<input type="text" validtype="account[8,20]" /><br />
??? 漢子驗證:<input type="text" validtype="CHS" /><br />
??? 長途驗證:<input type="text" validtype="remote[""checkname.aspx"",""name""]" invalidMessage="用戶名已存在"/>
</body>
</html>
?
?
本身寫的validator.js
?
?
//擴大easyui表單的驗證
$.extend($.fn.validatebox.defaults.rules, {
??? //驗證漢子
??? CHS: {
??????? validator: function (value) {
??????????? return /^[\u0391-\uFFE5]+$/.test(value);
??????? },
??????? message: ""只能輸入漢字""
??? },
??? //移下手機號碼驗證
??? mobile: {//value值為文本框中的值
??????? validator: function (value) {
??????????? var reg = /^1[3|4|5|8|9]\d{9}$/;
??????????? return reg.test(value);
??????? },
??????? message: ""輸入手機號碼格局不正確.""
??? },
??? //國內郵編驗證
??? zipcode: {
??????? validator: function (value) {
??????????? var reg = /^[1-9]\d{5}$/;
??????????? return reg.test(value);
??????? },
??????? message: ""郵編必須長短0開端的6位數字.""
??? },
??? //用戶賬號驗證(只能包含 _ 數字 字母)
??? account: {//param的值為[]中值
??????? validator: function (value, param) {
??????????? if (value.length < param[0] || value.length > param[1]) {
??????????????? $.fn.validatebox.defaults.rules.account.message = ""用戶名長度必須在"" + param[0] + ""至"" + param[1] + ""局限"";
??????????????? return false;
??????????? } else {
??????????????? if (!/^[\w]+$/.test(value)) {
??????????????????? $.fn.validatebox.defaults.rules.account.message = ""用戶名只能數字、字母、下劃線構成."";
??????????????????? return false;
??????????????? } else {
??????????????????? return true;
??????????????? }
??????????? }
??????? }, message: """"
??? }
})
?
?
?
?
checkname.aspx
?
?
<%@ Page Language="C#" %>
<script runat="server">
??? void Page_Load(object sender, System.EventArgs e)
??? {
??????? if (!string.IsNullOrEmpty(Request["name"]))
??????? {
??????????? string name = "";
??????????? name = Request["name"];
??????????? if (name == "zhxhdean")
??????????? {//當文本框中值為 zhxhdean,提示用戶已存在。 這一步可以去數據庫查詢
??????????????? Response.Write("false");
??????????????? return;
?????? ?????}
??????????? else
??????????? {
??????????????? Response.Write("true");
??????????????? return;
??????????? }
??????? }
??? }
</script>
轉載于:https://blog.51cto.com/8753762/1549413
總結
以上是生活随笔為你收集整理的easyui validatebox 验证类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 生产库自动派送报表派送失败之重新派送
- 下一篇: ln链接使用