exp.validate.js
简单实用的js基础数据验证
prototype
/// <reference path="/Scripts/expand-fn/exp_validate.js" />
/*数据验证 liuph 2015-03-03
扩展String方法
*/ //验证整数
String.prototype.exp_isInt = function () {
return /^[+-]?\d+$/.test(this);
}
//验证正整数
String.prototype.exp_isIntT = function () {
return /^\d+$/.test(this) && this != 0;
}
//验证非负整数
String.prototype.exp_isIntN = function () {
return /^\d+$/.test(this);
}
//验证负整数
String.prototype.exp_isIntF = function () {
return /^-\d+$/.test(this);
}
//验证小数
String.prototype.exp_isFloat = function () {
return /^[+-]?\d+(.\d+)*$/.test(this);
}
//验证正小数
String.prototype.exp_isFloatT = function () {
return /^\d+(.\d+)*$/.test(this) && this != 0;
}
//验证非负小数
String.prototype.exp_isFloatN = function () {
return /^\d+(.\d+)*$/.test(this);
}
//验证负小数
String.prototype.exp_isFloatF = function () {
return /^-\d+(.\d+)*$/.test(this);
} //中文
String.prototype.exp_isCN = function () {
return /^[\u4e00-\u9fa5]+$/.test(this);
}
//英文
String.prototype.exp_isEN = function () {
return /^[a-zA-Z]+$/.test(this);
}
//数字
String.prototype.exp_isNum = function () {
return /^[0-9]+$/.test(this);
}
//中文英文数字
String.prototype.exp_isStr = function () {
return /^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(this);
}
//中文英文数字下划线横线
String.prototype.exp_isStr1 = function () {
return /^[\u4e00-\u9fa5a-zA-Z0-9\_\-]+$/.test(this);
} //手机号码(需更新)
String.prototype.exp_isPhone = function () {
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);
}
//电话 区号-电话-分机号 分机号可不写
String.prototype.exp_isTel = function () {
return /^[0][1-9][0-9]{1,2}[\-\*]?[1-9][0-9]{6,7}([-][0-9]+)*$/.test(this);
}
//电子邮箱
String.prototype.exp_isEmail = function () {
return /^[a-zA-Z0-9\_\.]+@[a-zA-Z0-9]+\.[a-zA-Z]+(\.[a-zA-Z]+)*$/.test(this);
} //长度 min最小长度(包含) max最大长度(包含)
String.prototype.exp_isLength = function (min, max) {
var valMin = min == null ? true : this.length > min - 1;
var valMax = max == null ? true : this.length < max + 1;
return valMin && valMax;
}
//去除前后空格
String.prototype.exp_Trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去除前空格
String.prototype.exp_TrimL = function () {
return this.replace(/^\s/g, "");
}
//去除后空格
String.prototype.exp_TrimR = function () {
return this.replace(/\s*$/g, "");
}
//去除所有空格
String.prototype.exp_TrimA = function () {
return this.replace(/\s/g, "");
}
//密码强度 0空/1弱/2中/3强
String.prototype.exp_PwdLevel = function (pwd) {
var num = pwd.replace(/[^0-9]/g, "").length;/*数字个数*/
var en = pwd.replace(/[^a-zA-Z]/g, "").length;/*字母个数*/
var punctuation = pwd.replace(/[0-9a-zA-Z]/g, "").length;/*标点个数*/
return (num > 0 ? 1 : 0) + (en > 0 ? 1 : 0) + (punctuation > 0 ? 1 : 0)
}
//获取地址栏值 null
String.prototype.exp_GetQueryString =function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
exp_validate.js
function
/// <reference path="/Scripts/expand-fn/exp.validate.js" />
/*数据验证 liuph 2015-03-03
直接使用全局变量expV.方法
*/
var expV = {};
//验证整数
expV.isInt = function (str) {
return /^[+-]?\d+$/.test(str);
}
//验证正整数
expV.isIntT = function (str) {
return /^\d+$/.test(str) && str != 0;
}
//验证非负整数
expV.isIntN = function (str) {
return /^\d+$/.test(str);
}
//验证负整数
expV.isIntF = function (str) {
return /^-\d+$/.test(str);
}
//验证小数
expV.isFloat = function (str) {
return /^[+-]?\d+(.\d+)*$/.test(str);
}
//验证正小数
expV.isFloatT = function (str) {
return /^\d+(.\d+)*$/.test(str) && str != 0;
}
//验证非负小数
expV.isFloatN = function (str) {
return /^\d+(.\d+)*$/.test(str);
}
//验证负小数
expV.isFloatF = function (str) {
return /^-\d+(.\d+)*$/.test(str);
} //中文
expV.isCN = function (str) {
return /^[\u4e00-\u9fa5]+$/.test(str);
}
//英文
expV.isEN = function (str) {
return /^[a-zA-Z]+$/.test(str);
}
//数字
expV.isNum = function (str) {
return /^[0-9]+$/.test(str);
}
//中文英文数字
expV.isStr = function (str) {
return /^[\u4e00-\u9fa5a-zA-Z0-9]+$/.test(str);
}
//中文英文数字下划线横线
expV.isStr1 = function (str) {
return /^[\u4e00-\u9fa5a-zA-Z0-9\_\-]+$/.test(str);
} //手机号码(需更新)
expV.isPhone = function (str) {
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);
}
//仅作宽松验证
expV.isPhone1 = function (str) {
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);
}
//电话 区号-电话-分机号 分割用-或* 分机号可不写
expV.isTel = function (str) {
return /^[0][1-9][0-9]{1,2}[\-\*]?[1-9][0-9]{6,7}([-][0-9]+)*$/.test(str);
}
//电子邮箱
expV.isEmail = function (str) {
return /^[a-zA-Z0-9\_\.]+@[a-zA-Z0-9]+\.[a-zA-Z]+(\.[a-zA-Z]+)*$/.test(str);
} //长度 min最小长度(包含) max最大长度(包含)
expV.isLength = function (str, min, max) {
var valMinmin = (min == null ? true : str.length > min - 1);
var valMaxmax = (max == null ? true : str.length < max + 1);
return valMin && valMax;
}
//去除前后空格
expV.Trim = function (str) {
return str.replace(/(^\s*)|(\s*$)/g, "");
}
//去除前空格
expV.TrimL = function (str) {
return str.replace(/^\s/g, "");
}
//去除后空格
expV.TrimR = function (str) {
return str.replace(/\s*$/g, "");
}
//去除所有空格
expV.TrimA = function (str) {
return str.replace(/\s/g, "");
}
//密码强度 0空/1弱/2中/3强
expV.PwdLevel = function PwdLevel(pwd) {
var num = pwd.replace(/[^0-9]/g, "").length;/*数字个数*/
var en = pwd.replace(/[^a-zA-Z]/g, "").length;/*字母个数*/
var punctuation = pwd.replace(/[0-9a-zA-Z]/g, "").length;/*标点个数*/
return (num > 0 ? 1 : 0) + (en > 0 ? 1 : 0) + (punctuation > 0 ? 1 : 0)
}
//获取地址栏值 null
expV.GetQueryString = function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
exp.validate.js
exp.validate.js的更多相关文章
- 插件—jquery.validate.js
前言 在学习jquery.validate.js中的一个小案例,只是这个插件的简单使用. 案例代码如下: <head> <title></title> ...
- 修改 jquery.validate.js 支持非form标签
尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...
- 表单验证插件之jquery.validate.js
提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...
- Jquery客户端校验——jquery.validate.js
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证 ...
- MVC validate.js下使用 ajaxSubmit
首页定义验证实体 using System.ComponentModel.DataAnnotations; using System.Web.Mvc; namespace MvcApplication ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- jquery.validate.js插件使用
jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...
- jquery.validate.js表单验证
一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...
- jQuery验证控件jquery.validate.js使用说明+中文API
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 学习 ...
随机推荐
- APUE包含头文件"apue.h"问题
下载源码 从unix高级编程书籍官网下载书籍的上的所有源码. wget http://www.apuebook.com/src.tar.gz 解压这个文件 tar -zxvf src.tar.gz 解 ...
- win7 快捷键
F F1 显示辅助 F2 重命名选定项目 F3 搜索文件或文件夹 F4 在 Windows 资源管理器中显示地址栏列表 F5 刷新活动窗口 F6 在窗口中或桌面上循环切换屏幕元素 F10 激活活动程序 ...
- 【rqnoj378】 约会计划
题目描述 cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而,最关键的是,cc能够很好的调解各各妹妹间的关系.mm之间的关系及其复杂,cc必须严格 ...
- 查看mysql的安装信息
查看mysql的安装信息: #ps -ef | grep mysql usr/bin/mysql 是指:mysql的运行路径 var/lib/mysql 是指:mysql数据库文件的存放路径 usr/ ...
- Attribute在.net编程中的应用
Attribute FYI Link: Attribute在.net编程中的应用(一) Attribute在.net编程中的应用(二) Attribute在.net编程中的应用(三) Attribut ...
- 内核终端判断,微信?QQ?ipad?IE?移动?Google?opera……
$(document).ready(function(){ //判断访问终端 var browser={ versions:function(){ var u = navigator.userAgen ...
- canvas 3D运动球效果
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- CentOS7安装docker出错(Transaction check error)
1. 出错内容: Transaction check error: :-.el7_2..x86_64 conflicts with :-.el7.x86_64 :-.el7_2..x86_64 con ...
- json日期格式问题的办法
//json日期转换 格式(2015-01-01) <input class="easyui-datebox" name="sbdj_txtShebaoka_Lin ...
- CentOS增加swap分区
使用dd命令创建一个swap分区 [root@localhost Desktop]#dd if=/dev/zero of=/home/swap bs=1024 count=1048576 count的 ...