exp.validate.js
简单实用的js基础数据验证
prototype
1 /// <reference path="/Scripts/expand-fn/exp_validate.js" /> 2 /*数据验证 liuph 2015-03-03 3 扩展String方法 4 */ 5 6 //验证整数 7 String.prototype.exp_isInt = function () { 8 return /^[+-]?\d+$/.test(this); 9 } 10 //验证正整数 11 String.prototype.exp_isIntT = function () { 12 return /^\d+$/.test(this) && this != 0; 13 } 14 //验证非负整数 15 String.prototype.exp_isIntN = function () { 16 return /^\d+$/.test(this); 17 } 18 //验证负整数 19 String.prototype.exp_isIntF = function () { 20 return /^-\d+$/.test(this); 21 } 22 //验证小数 23 String.prototype.exp_isFloat = function () { 24 return /^[+-]?\d+(.\d+)*$/.test(this); 25 } 26 //验证正小数 27 String.prototype.exp_isFloatT = function () { 28 return /^\d+(.\d+)*$/.test(this) && this != 0; 29 } 30 //验证非负小数 31 String.prototype.exp_isFloatN = function () { 32 return /^\d+(.\d+)*$/.test(this); 33 } 34 //验证负小数 35 String.prototype.exp_isFloatF = function () { 36 return /^-\d+(.\d+)*$/.test(this); 37 } 38 39 //中文 40 String.prototype.exp_isCN = function () { 41 return /^[\u4e00-\u9fa5]+$/.test(this); 42 } 43 //英文 44 String.prototype.exp_isEN = function () { 45 return /^[a-zA-Z]+$/.test(this); 46 } 47 //数字 48 String.prototype.exp_isNum = function () { 49 return /^[0-9]+$/.test(this); 50 } 51 //中文英文数字 52 String.prototype.exp_isStr = function () { 53 return /^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(this); 54 } 55 //中文英文数字下划线横线 56 String.prototype.exp_isStr1 = function () { 57 return /^[\u4e00-\u9fa5a-zA-Z0-9\_\-]+$/.test(this); 58 } 59 60 //手机号码(需更新) 61 String.prototype.exp_isPhone = function () { 62 return /^1((([3,8][0-9]|[5][0-3,5-9]|[7][6-8])[0-9]{8})|[7][0][0,5,9][0-9]{7})$/.test(this); 63 } 64 //电话 区号-电话-分机号 分机号可不写 65 String.prototype.exp_isTel = function () { 66 return /^[0][1-9][0-9]{1,2}[\-\*]?[1-9][0-9]{6,7}([-][0-9]+)*$/.test(this); 67 } 68 //电子邮箱 69 String.prototype.exp_isEmail = function () { 70 return /^[a-zA-Z0-9\_\.]+@[a-zA-Z0-9]+\.[a-zA-Z]+(\.[a-zA-Z]+)*$/.test(this); 71 } 72 73 //长度 min最小长度(包含) max最大长度(包含) 74 String.prototype.exp_isLength = function (min, max) { 75 var valMin = min == null ? true : this.length > min - 1; 76 var valMax = max == null ? true : this.length < max + 1; 77 return valMin && valMax; 78 } 79 //去除前后空格 80 String.prototype.exp_Trim = function () { 81 return this.replace(/(^\s*)|(\s*$)/g, ""); 82 } 83 //去除前空格 84 String.prototype.exp_TrimL = function () { 85 return this.replace(/^\s/g, ""); 86 } 87 //去除后空格 88 String.prototype.exp_TrimR = function () { 89 return this.replace(/\s*$/g, ""); 90 } 91 //去除所有空格 92 String.prototype.exp_TrimA = function () { 93 return this.replace(/\s/g, ""); 94 } 95 //密码强度 0空/1弱/2中/3强 96 String.prototype.exp_PwdLevel = function (pwd) { 97 var num = pwd.replace(/[^0-9]/g, "").length;/*数字个数*/ 98 var en = pwd.replace(/[^a-zA-Z]/g, "").length;/*字母个数*/ 99 var punctuation = pwd.replace(/[0-9a-zA-Z]/g, "").length;/*标点个数*/ 100 return (num > 0 ? 1 : 0) + (en > 0 ? 1 : 0) + (punctuation > 0 ? 1 : 0) 101 } 102 //获取地址栏值 null 103 String.prototype.exp_GetQueryString =function GetQueryString(name) { 104 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 105 var r = window.location.search.substr(1).match(reg); 106 if (r != null) return unescape(r[2]); return null; 107 }
exp_validate.js
function
1 /// <reference path="/Scripts/expand-fn/exp.validate.js" /> 2 /*数据验证 liuph 2015-03-03 3 直接使用全局变量expV.方法 4 */ 5 var expV = {}; 6 //验证整数 7 expV.isInt = function (str) { 8 return /^[+-]?\d+$/.test(str); 9 } 10 //验证正整数 11 expV.isIntT = function (str) { 12 return /^\d+$/.test(str) && str != 0; 13 } 14 //验证非负整数 15 expV.isIntN = function (str) { 16 return /^\d+$/.test(str); 17 } 18 //验证负整数 19 expV.isIntF = function (str) { 20 return /^-\d+$/.test(str); 21 } 22 //验证小数 23 expV.isFloat = function (str) { 24 return /^[+-]?\d+(.\d+)*$/.test(str); 25 } 26 //验证正小数 27 expV.isFloatT = function (str) { 28 return /^\d+(.\d+)*$/.test(str) && str != 0; 29 } 30 //验证非负小数 31 expV.isFloatN = function (str) { 32 return /^\d+(.\d+)*$/.test(str); 33 } 34 //验证负小数 35 expV.isFloatF = function (str) { 36 return /^-\d+(.\d+)*$/.test(str); 37 } 38 39 //中文 40 expV.isCN = function (str) { 41 return /^[\u4e00-\u9fa5]+$/.test(str); 42 } 43 //英文 44 expV.isEN = function (str) { 45 return /^[a-zA-Z]+$/.test(str); 46 } 47 //数字 48 expV.isNum = function (str) { 49 return /^[0-9]+$/.test(str); 50 } 51 //中文英文数字 52 expV.isStr = function (str) { 53 return /^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(str); 54 } 55 //中文英文数字下划线横线 56 expV.isStr1 = function (str) { 57 return /^[\u4e00-\u9fa5a-zA-Z0-9\_\-]+$/.test(str); 58 } 59 60 //手机号码(需更新) 61 expV.isPhone = function (str) { 62 return /^1((([3,8][0-9]|[5][0-3,5-9]|[7][6-8])[0-9]{8})|[7][0][0,5,9][0-9]{7})$/.test(str); 63 } 64 //仅作宽松验证 65 expV.isPhone1 = function (str) { 66 return /^1((([3,8][0-9]|[5][0-3,5-9]|[7][6-8])[0-9]{8})|[7][0][0,5,9][0-9]{7})$/.test(str); 67 } 68 //电话 区号-电话-分机号 分割用-或* 分机号可不写 69 expV.isTel = function (str) { 70 return /^[0][1-9][0-9]{1,2}[\-\*]?[1-9][0-9]{6,7}([-][0-9]+)*$/.test(str); 71 } 72 //电子邮箱 73 expV.isEmail = function (str) { 74 return /^[a-zA-Z0-9\_\.]+@[a-zA-Z0-9]+\.[a-zA-Z]+(\.[a-zA-Z]+)*$/.test(str); 75 } 76 77 //长度 min最小长度(包含) max最大长度(包含) 78 expV.isLength = function (str, min, max) { 79 var valMinmin = (min == null ? true : str.length > min - 1); 80 var valMaxmax = (max == null ? true : str.length < max + 1); 81 return valMin && valMax; 82 } 83 //去除前后空格 84 expV.Trim = function (str) { 85 return str.replace(/(^\s*)|(\s*$)/g, ""); 86 } 87 //去除前空格 88 expV.TrimL = function (str) { 89 return str.replace(/^\s/g, ""); 90 } 91 //去除后空格 92 expV.TrimR = function (str) { 93 return str.replace(/\s*$/g, ""); 94 } 95 //去除所有空格 96 expV.TrimA = function (str) { 97 return str.replace(/\s/g, ""); 98 } 99 //密码强度 0空/1弱/2中/3强 100 expV.PwdLevel = function PwdLevel(pwd) { 101 var num = pwd.replace(/[^0-9]/g, "").length;/*数字个数*/ 102 var en = pwd.replace(/[^a-zA-Z]/g, "").length;/*字母个数*/ 103 var punctuation = pwd.replace(/[0-9a-zA-Z]/g, "").length;/*标点个数*/ 104 return (num > 0 ? 1 : 0) + (en > 0 ? 1 : 0) + (punctuation > 0 ? 1 : 0) 105 } 106 //获取地址栏值 null 107 expV.GetQueryString = function GetQueryString(name) { 108 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); 109 var r = window.location.search.substr(1).match(reg); 110 if (r != null) return unescape(r[2]); return null; 111 }
exp.validate.js
转载于:https://www.cnblogs.com/liuph/p/4312498.html
exp.validate.js相关推荐
- jQuery验证控件jquery.validate.js使用说明+中文API
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- jq.validate.js
首选必须是要下载滴,jq.validate.js表单效验方式. 建立form表单没得说 <form id="form"><p><label for=& ...
- jQuery.validate.js API
为什么80%的码农都做不了架构师?>>> jQuery.validate.js API 转载于:https://my.oschina.net/azheng/blog/10281
- jQuery表单校验jquery.validate.js的使用
jQuery是一个快速.简洁的js库,为网站的快速开发简化了HTML文档遍历,事件处理,动画,以及Ajax交互.使用jQuery将极大的提高编写javascript代码的效率, 让写出来的代码更加优雅 ...
- jquery.validate.js插件的使用方法
近期做项目.须要用到 jQuery.validate.js插件,于是记录一下工作中的一些经验,以便日后学习. [样例例如以下] 1.前台页面 <form id="form1" ...
- ASP.NETmvc常用JQUERY收藏【jquery.form.js结合jquery.validate.js】
虽然jquery.form.js可以通过自定义验证方式实现个性化的验证,不过我们大量使用的还不是一个红星(*) 在jquery.form.js下使用jquery.validate.js就可以简简单单的 ...
- 当同时使用bootstrap-datepicker.js和jquery.validate.js这两款插件,至少要选择两次时间,才能验证成功的问题...
当用 bootstrap-datepicker.js 这个插件选择时间,再用jquery.validate.js进行验证,当时间不为空时则验证通过.可能由于在时间插件弹出来时,input框的值发生改变 ...
- 修改 jquery.validate.js 支持非form标签
尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...
- 使用validate.js实现表单数据验证
ASP.NET关于表单验证,目前知道的,除了以前那种傻瓜式的每个表单选项都用一个函数去验证之外,有两种方法是比较方便的,今天先介绍一下第一种,在前端实现表单验证的方法--基于validate.js的表 ...
最新文章
- ASP.NET文件的下载
- c语言程序中变量先引用声明,C语言如何跨文件调用函数定义中声明的变量
- 通用Windows应用《博客园-开发者的网上家园》开发(1)——MVVM模式
- HoughLinesP函数(概率检测直线)
- array关于map,reduce,filter的用法
- I2S和PCM区别(二十)
- 华硕笔记本linux触摸板驱动,华硕笔记本触摸板驱动安装教程及打开方法
- Viso各版本网盘免费下载
- 教你webm格式怎么转换成mp4
- 风口猪炒股指标_低吸大长腿
- EDEM颗粒堆积fluent meshing网格生成
- 云通信接口更新迭代——SUBMAIL API V4正式上线
- 2021最新凡诺免费企业网站管理系统PHP版 v3.4网站源码
- twitter_关于Twitter和激进化的警告
- ssms 导出mysql_怎样使用SSMS管理器导出数据表 用SSMS管理器导出数据表的方法
- Windows11关机键在哪 Win11系统关机键的位置
- python 查找二维数组长度_Python二维数组中的查找
- Java 常用正则表达式与测试
- 台积电:3纳米芯片工厂地址首选台湾 美国次之
- 口红会染唇是什么意思_口红和唇釉有什么区别
热门文章
- python tcp服务器模板_python socket之tcp服务器与客户端示例
- PTA7、 转换函数使用 (10 分)
- java日志怎么实现_JAVA项目中怎么实现一个通用日志记录功能
- 解决ubuntu和windows之间无法复制粘贴问题
- 域 正在应用计算机设置,入域的时候卡在”正在应用计算机设置”持续了好几分钟...
- java 建表 框架_【Java框架型项目从入门到装逼】第九节 - 数据库建表和CRUD操作...
- v-for和v-if的问题
- 使用帅气的cordic算法进行坐标系互转及log10的求解
- Window中显示文件扩展名
- 算法导论2.1-2.3 部分答案