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库,还有里面功能太多,感觉不太符合自己的需求.最 ...
随机推荐
- ES聚合实例
在es中需要根据app_categor进行聚合,JSON查询语句如下: { "query": { "bool": { "must": [ { ...
- The app icon set named "AppIcon" did not have any applicable content.
Develop Tools: xCode 5.1 I write a demo for app settings feature. The tutorial url is here. When I a ...
- 转:MongoDB调查总结
与关系型数据库相比,MongoDB的优点:①弱一致性(最终一致),更能保证用户的访问速度:举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的精确值 ...
- asp.net framework identity 学习笔记
关于 cookie expiry & securityStamp http://www.jamessturtevant.com/posts/ASPNET-Identity-Cookie-Aut ...
- onCreateOptionsMenu与onCreateContextMenu差别
onCreateOptionsMenu只会在启动时调用一次,而onCreateContextMenu则每次都会调用,这是因为onCreateContextMenu需要为所有的View控件的上下文菜单服 ...
- RR 和RC 幻读问题
<pre name="code" class="html">显然 RR 支持 gap lock(next-key lock),而RC则没有gap l ...
- 【动态规划】XMU 1588 01序列计数
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1588 题目大意: 给n1个0和n2个1,连续的0不超过k1个,连续的1不超过k2个.问 ...
- 调用test case集,并生成测试报告
结构是 test_all.py 进行配置,执行所有测试用例集,并合并测试报告到同一个文件 #test_all.py 进行配置,执行所有测试用例集 # coding = utf-8 from time ...
- Application之图书馆
前两天小编讲的都是些比较隐私的东西,为啥隐私?因为它俩(cookie和session)都只有用户自已才能使用和访问,今天小编来介绍个比较开放点的东西给大家. 小编虽已脱下学生服装多年,但如今忆起当年校 ...
- UIAlertController 的使用——NS_CLASS_AVAILABLE_IOS(8_0)
UIAlertView 随着苹果上次iOS 5的发布,对话框视图样式出现在了我们面前,直到现在它都没有发生过很大的变化.下面的代码片段展示了如何初始化和显示一个带有“取消”和“好的”按钮的对话框视图. ...