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库,还有里面功能太多,感觉不太符合自己的需求.最 ...
随机推荐
- laravel框架——保存用户登陆信息(session)
public function inlog(Request $request) { //获取表单提交的数据 $input = $request->all(); //根本获取的数据去数据库中查询 ...
- laravel框架——表单验证
创建路由 Route::get('test','VerController@index'); Route::post('tosubmit','VerController@tosubmit'); 在控制 ...
- codevs 4768 跳石头
传送门 表示去年不会,二分是啥都不知道,一脸懵逼. 今年再做,虽然知道二分是啥了,但依旧不会,蒙蔽了好几天,最后还是看了题解. #include<cstdio> #define M 510 ...
- mysql常用的命令大全
常用的MySQL命令大全一.连接MySQL格式: mysql -h主机地址 -u用户名 -p用户密码1.例1:连接到本机上的MYSQL.首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令 ...
- delphi操作文本文件的方法简介
delphi操作文本文件的方法简介减小字体 增大字体 作者佚名来源不详发布时间2008-5-31 10:31:16发布人xuedelphi1 文件类型和标准过程 Delphi同Object ...
- #include <sys/stat.h>的作用
#include <sys/stat.h> 文件状态, 是unix/linux系统定义文件状态所在的伪标准头文件. 含有类型与函数: dev_t st_dev Device ...
- Android之路-------Activity的详解
前言 由于接近放假,公司在赶项目所以前段LP比较忙,没什么时间总结和写博客,只是准备睡觉的时候看看书,每天看的不算多,大概10多页左右吧,不过每天坚持如此的话那也是一个庞大的数字. 今天LP的任务完成 ...
- bitree
#include "stdio.h" #include "stdlib.h" #define OVERFLOW -1 #define ERROR -1 #def ...
- oracle-TNS是什么?
oracle 的 TNS 是什么的缩写?Transparent Network Substrate(透明网络底层,即无论底层的网络层用什么协议对于上层的应用层都是透明的,也即上层的应用层不用关心底层的 ...
- Java与.net的区别delegate和event
There is no delegate concept in Java The right-side C# program may be mimiced with reflection techno ...