js的相关验证
1 var JavaScriptCommon = {
/*身份证号码校验*/
VerifyID: function (socialNo) {
if (socialNo == "") { return (false); }
&& socialNo.length != ) { return (false); }
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : "国外"
};
, ))] == null) { return (false); }
) {
pattern = /^\d{}$/; if (pattern.exec(socialNo) == null) { return (false); }
, )); , ); , )); switch (month) {
) { return false; }
) { return false; }
== && birth % != ) || birth % == ) { ) { ) { return false; } }
break; default: return false;
}
|| nowYear - parseInt(birth) > ) { return false; }
return (true);
}
, , , , , , , , , , , , , , , , , ); ; ; ; ; i < ; ++i) {
') { return (false); }
'; }
lSum += nNum * Wi[i];
}
) == ) == * Wi[]; }
) < ) > ') { return (false); }
) - ]; }
) == ) { return true; }
else { return (false); }
},
/*手机号码校验*/
isMobile: function (a) {
[]\d{}$/).test(a);
},
//乘法函数,用来得到精确的乘法结果
//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用:accMul(arg1,arg2)
//返回值:arg1乘以arg2的精确结果
accMul: function (arg1, arg2) {
, s1 = arg1.toString(), s2 = arg2.toString();
].length } catch (e) { }
].length } catch (e) { }
, m);
},
//除法函数,用来得到精确的除法结果
//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
//调用:accDiv(arg1,arg2)
//返回值:arg1除以arg2的精确结果
accDiv: function (arg1, arg2) {
, t2 = , r1, r2;
].length } catch (e) { }
].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""));
r2 = Number(arg2.toString().replace(".", ""));
, t2 - t1);
if (result == Infinity) {
result = ;
}
return result;
}
},
//加法函数,用来得到精确的加法结果
//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用:accAdd(arg1,arg2)
//返回值:arg1加上arg2的精确结果
accAdd: function (arg1, arg2) {
var r1, r2, m;
].length } }
].length } }
m = Math.pow(, Math.max(r1, r2));
return (arg1 * m + arg2 * m) / m;
},
// 减法函数
accSub: function accSub(arg1, arg2) {
));
},
GetRequest: function () {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
) {
);
strs = str.split("&");
; i < strs.length; i++) {
theRequest[strs[i].split(]] = (strs[i].split(]);
}
}
return theRequest;
}
};
/*
String
*/
String.prototype.IsEmpty = function () {
return this == null || typeof (this) == "undefined" || this == "";
}
String.prototype.IsNumber = function () {
-]+$/;
return reg.test(this);
}
String.prototype.IsIdentity = function () {
return JavaScriptCommon.VerifyID(this);
}
String.prototype.IsDecimal = function () {
-]+(.[-]{,})?$/;
return reg.test(this);
}
String.prototype.IsEnglish = function () {
var reg = /^C_\w+$/;
return reg.test(this);
}
//添加验证0~1之间小数
String.prototype.isPercernt = function () {
]+(.[-]{,})?$|$/;
return reg.test(this);
}
String.prototype.IsDate = function () {
var regex = new RegExp("^(?:(?:([0-9]{4}(-|\/)(?:(?:0?[1,3-9]|1[0-2])(-|\/)(?:29|30)|((?:0?[13578]|1[02])(-|\/)31)))|([0-9]{4}(-|\/)(?:0?[1-9]|1[0-2])(-|\/)(?:0?[1-9]|1\\d|2[0-8]))|(((?:(\\d\\d(?:0[48]|[2468][048]|[13579][26]))|(?:0[48]00|[2468][048]00|[13579][26]00))(-|\/)0?2(-|\/)29))))$");
return regex.test(this);
}
String.prototype.IsMobile = function () {
[]\d{}$/;
return reg.test(this);
}
String.prototype.IsTelePhone = function () {
\d{,})-)?(\d{,})(-(\d{,}))?$/;
return reg.test(this);
}
String.prototype.IsEmail = function () {
,}){,})$/;
return reg.test(this);
}
String.prototype.ToNumber = function () {
: parseInt(this);
}
String.prototype.ToFloat = function () {
: parseFloat(this);
}
String.prototype.ToDate = function () {
var newDate = this.ToDateTime();
);
}
getDate = function (strDate) {
var date = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/,
function (a) { ) - ; }).match(/\d+/g) + ')');
return date;
}
String.prototype.ToDateTime = function () {
var ars = new Array();
) {
ars = ].split('/');
}
else {
ars = ].split('-')
}
], ars[], ars[]);
return newDate;
}
String.prototype.LRAllTrim = function () {
return this.replace(/\s/g, "");
}
// 日期处理所需的公用函数
function appendZero(n) {
));
}
/*
//取得指定日期的年月日时分秒
//参数:dateValue 是格式形如:2007/04/05
function TimeCom(dateValue) {
var newCom = new Date(dateValue);
this.year = newCom.getFullYear();
this.month = newCom.getMonth() + 1;
this.day = newCom.getDate();
this.hour = newCom.getHours();
this.minute = newCom.getMinutes();
this.second = newCom.getSeconds();
this.msecond = newCom.getMilliseconds();
this.week = newCom.getDay();
}
*/
// 日期格式化(0:2000年10月20日 1:2000-10-20 2:2000-10-20 30:24:00)
Date.prototype.MyFormat = function (formattype) {
var day = this;
var dateString = "";
var thisyear = day.FormatYear();
);
var thisday = appendZero(day.getDate());
var thishour = appendZero(day.getHours());
var thismin = appendZero(day.getMinutes());
var thissec = appendZero(day.getSeconds());
switch (formattype) {
:
dateString = thisyear + "年" + thismonth + "月" + thisday + "日";
break;
:
dateString = thisyear + "-" + thismonth + "-" + thisday;
break;
:
dateString = thisyear + "-" + thismonth + "-" + thisday + " " + appendZero(thishour) + ":" + appendZero(thismin) + ":" + appendZero(thissec);
break;
default:
dateString = thisyear + "-" + thismonth + "-" + thisday;
}
return dateString;
}
// 日期格式化(0:2000年10月20日 1:2000-10-20 2:2000-10-20 30:24:00)
Date.prototype.Format = function (formattype) {
var day = this;
var dateString = "";
var thisyear = day.FormatYear();
var thismonth = appendZero(day.getMonth());
var thisday = appendZero(day.getDate());
var thishour = appendZero(day.getHours());
var thismin = appendZero(day.getMinutes());
var thissec = appendZero(day.getSeconds());
switch (formattype) {
:
dateString = thisyear + "年" + thismonth + "月" + thisday + "日";
if (dateString == "2900年01月01日") {
dateString = "永久有效";
}
if (dateString == "1900年01月01日") {
dateString = "未设置";
}
break;
:
") {
thismonth = ";
thisyear = accSub(thisyear, );
}
dateString = thisyear + "-" + thismonth + "-" + thisday;
if (dateString == "2900-01-01") {
dateString = "永久有效";
}
if (dateString == "1900-01-01") {
dateString = "未设置";
}
break;
:
dateString = thisyear + "-" + thismonth + "-" + thisday + " " + appendZero(thishour) + ":" + appendZero(thismin) + ":" + appendZero(thissec);
if (dateString == "2900-01-01 00:00:00") {
dateString = "永久有效";
}
if (dateString == "1900-01-01 00:00:00") {
dateString = "未设置";
}
break;
default:
dateString = thisyear + "-" + thismonth + "-" + thisday;
if (dateString == "2900-01-01") {
dateString = "永久有效";
}
if (dateString == "1900-01-01") {
dateString = "未设置";
}
}
return dateString;
}
Date.prototype.FormatYear = function () {
var theYear = this.getFullYear();
);
) {
tmpYear += ;
) {
tmpYear += ;
}
}
if (tmpYear < this.MinYear) {
tmpYear = this.MinYear;
}
if (tmpYear > this.MaxYear) {
tmpYear = this.MaxYear;
}
return (tmpYear);
}
// 在当前日期基础上增加指定的值
//参数:interval : y或year-表示取得相差的年份 n或month-表示相差的月份 d或day表示相差的天数 h或hour-表示相差的小时 m或minute-表示相差的分钟 s或second-表示相差的秒数 ms或msecond-表示相差的毫秒数 w或week-表示相差的周数
// num是偏移值,-表示向前推,+向后推
// dateValue 指定的日期
// formattype是返回的时间类型
//返回:返回时间串
Date.prototype.Add = function (interval, num) {
var newCom = new TimeCom(this);
switch (String(interval).toLowerCase()) {
case "y": case "year": newCom.year += num; break;
case "n": case "month": newCom.month += num; break;
case "d": case "day": newCom.day += num; break;
case "h": case "hour": newCom.hour += num; break;
case "m": case "minute": newCom.minute += num; break;
case "s": case "second": newCom.second += num; break;
case "ms": case "msecond": newCom.msecond += num; break;
; break;
default: return ("invalid");
}
var now = newCom.year + "/" + newCom.month + "/" + newCom.day + " " + newCom.hour + ":" + newCom.minute + ":" + newCom.second;
return new Date(now);
}
// 指定小数位数的四舍五入
Number.prototype.Round = function (v) {
, v);
return Math.round(this * vv) / vv;
}
// 检测文本框输入只能是正数Float类型
function isFloatPositive(jQuerySelector) {
-]*[-][-]*$/; //^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$正浮点数(8位小数)^\d+(\.\d+)?$
//确保用户输入的是正实数
if (isNaN($(jQuerySelector).val())) { $(jQuerySelector).val(''); return false; }
if (!numFloatPositive.test($(jQuerySelector).val()) && $(jQuerySelector).val() != '') {
document.execCommand('undo'); //确保用户输入的是正实数
return false;
}
return true;
}
//转换Json时间格式,如:/Date(1462269529000)/
function timeStamp2String(time) {
var data = time;
));
var year = datetime.getFullYear();
< ? ) : datetime.getMonth() + ;
? " + datetime.getDate() : datetime.getDate();
? " + datetime.getHours() : datetime.getHours();
? " + datetime.getMinutes() : datetime.getMinutes();
? " + datetime.getSeconds() : datetime.getSeconds();
return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}
js的相关验证的更多相关文章
- JS表单验证-12个常用的JS表单验证
JS表单验证-12个常用的JS表单验证 最近有个项目用到了表单验证,小编在项目完结后的这段时间把常用的JS表单验证demo整理了一下,和大家一起分享~~~ 1. 长度限制 <p>1. 长度 ...
- js 表单验证控制代码大全
js表单验证控制代码大全 关键字:js验证表单大全,用JS控制表单提交 ,javascript提交表单:目录:1:js 字符串长度限制.判断字符长度 .js限制输入.限制不能输入.textarea 长 ...
- jquery.validation.js 表单验证
jquery.validation.js 表单验证 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuer ...
- Jquery.validate.js表单验证插件的使用
作为一个网站web开发人员,以前居然不知道还有表单验证这样好呀的插件,还在一行行写表单验证,真是后悔没能早点知道他们的存在. 最近公司不忙,自己学习一些东西的时候,发现了validation的一个实例 ...
- jquery.validate.js使用id验证控件
jquery.validate.js默认的是元素的name. 例如:<input name="username" id="username" size=& ...
- angular js 表单验证
<!doctype html> <html ng-app="myapp"> <head> <meta charset="UTF- ...
- JS表单验证类HTML代码实例
以前用的比较多的一个JS表单验证类,对于个人来说已经够用了,有兴趣的可以在此基础上扩展成ajax版本.本表单验证类囊括了密码验证.英文4~10个 字符验证. 中文非空验证.大于10小于100的数字.浮 ...
- 如何关闭eclipse对js xml的验证
经常会发现导入一些js框架,eclipse会编译报错 这是eclipse对js的瞎验证,如何解决呢? 关闭eclipse对js,xml的验证即可: 菜单Window - > Preference ...
- 一个自己实现的js表单验证框架。
经常要做一些表单验证的操作,每次都是用现成的框架,比如jquery,bootstrap等的验证插件,虽然也很强大,也很好用,可就是用起来需要引入许多js库,还有里面功能太多,感觉不太符合自己的需求.最 ...
随机推荐
- sort对二维字符数组排序(转)
由于二维字符数组的第二维没有赋值运算符,即不能对整个一维数组进行赋值,因此是无法直接对二维数组用sort进行排序的,解决办法有二种: 代码一: #include <iostream> #i ...
- java面试(毕业一年后准备换工作)
还记得一年前的今天,在网上投简历,找工作,当时找的工作的工作地点都在成都,其实自己挺想去外面工作几年的,如果毕业后就在成都工作,今后基本不可能去外省了, 所以刚好上海的一家外包公司来成都理工校招,导员 ...
- APP如何设计才能适配iphone6/plus和iphone5
随着苹果发布两种新尺寸的大屏iPhone 6,iOS平台尺寸适配问题终于还是来了,移动设计全面进入"杂屏"时代.看看下面三款iPhone尺寸和分辨率数据就知道屏幕有多杂了. 移动a ...
- springmvc参数类型转换三种方式
SpringMVC绑定参数之类型转换有三种方式: 1. 实体类中加日期格式化注解 @DateTimeFormat(pattern="yyyy-MM-dd hh:MM&quo ...
- Nhibernate 分页
public IList<Student> GetStudentByPage(int pageSize, int pageIndex, string SName) { ISession s ...
- jQuery插件infinitescroll参数【无限翻页】
转自:http://blog.163.com/penglie_520/blog/static/19440505020127255319862/ infinite-scroll-jquery 参数详解: ...
- activitie5 流程入门例子
流程这个东西在ERP项目用得比较多.在网上找到一个例子,与大家分享一下.http://yiyiboy2010.iteye.com/blog/1530924 感谢原博主提供 http://blog.ch ...
- 酷派D530刷机指引
酷派D530是我的第一台智能手机,刚入手的时候是挺激动的,什么Root啦,精简系统删官方应用啦,app2sd啦,杂七杂八的应用装了一堆,折腾得不亦乐乎.但过了那个热度之后,现在我对于智能手机的要求还是 ...
- 乱译文档--Musca介绍
胡乱翻译的,信,达,雅只能到达的水平.发现错误的话望留言好修改. 原文地址:http://aerosuidae.net/musca.html aerosuidae.net Musca 果蝇 A sim ...
- [Java] 实例创建的步骤
创建类的一个实例时,按照下面步骤进行创建: 1. 给当前类及其父.祖类的所有成员字段分配空间,并给它们赋予默认值 2. 开始执行当前类的构造器 3. 如果当前类有父类,则对父类创建一个实例:从第 2 ...