/**
* 检查输入的字符是否具有特殊字符
* 输入:str 字符串
* 返回:true 或 flase; true表示包含特殊字符
* 主要用于注册信息的时候验证
*/
function checkQuote(str){
var items = new Array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "{", "}", "[", "]", "(", ")");
items.push(":", ";", "'", "|", "\\", "<", ">", "?", "/", "<<", ">>", "||", "//");
items.push("admin", "administrators", "administrator", "管理员", "系统管理员");
items.push("select", "delete", "update", "insert", "create", "drop", "alter", "trancate");
str = str.toLowerCase();
for (var i = 0; i < items.length; i++) {
if (str.indexOf(items[i]) >= 0) {
return true;
}
}
return false;
}
/**************************************************************************************/
/*************************************时间的验证*****************************************/
/**************************************************************************************/
/**
* 检查日期格式是否正确
* 输入:str 字符串
* 返回:true 或 flase; true表示格式正确
* 注意:此处不能验证中文日期格式
* 验证短日期(2007-06-05)
*/
function checkDate(str){
//var value=str.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);
var value = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if (value == null) {
return false;
}
else {
var date = new Date(value[1], value[3] - 1, value[4]);
return (date.getFullYear() == value[1] && (date.getMonth() + 1) == value[3] && date.getDate() == value[4]);
}
}
/**
* 检查时间格式是否正确
* 输入:str 字符串
* 返回:true 或 flase; true表示格式正确
* 验证时间(10:57:10)
*/
function checkTime(str){
var value = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/)
if (value == null) {
return false;
}
else {
if (value[1] > 24 || value[3] > 60 || value[4] > 60) {
return false
}
else {
return true;
}
}
}
/**
* 检查全日期时间格式是否正确
* 输入:str 字符串
* 返回:true 或 flase; true表示格式正确
* (2007-06-05 10:57:10)
*/
function checkFullTime(str){
//var value = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
var value = str.match(/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/);
if (value == null) {
return false;
}
else {
//var date = new Date(checkFullTime[1], checkFullTime[3] - 1, checkFullTime[4], checkFullTime[5], checkFullTime[6], checkFullTime[7]);
//return (date.getFullYear() == value[1] && (date.getMonth() + 1) == value[3] && date.getDate() == value[4] && date.getHours() == value[5] && date.getMinutes() == value[6] && date.getSeconds() == value[7]);
return true;
}
}
/**************************************************************************************/
/************************************身份证号码的验证*************************************/
/**************************************************************************************/
/**
* 身份证15位编码规则:dddddd yymmdd xx p
* dddddd:地区码
* yymmdd: 出生年月日
* xx: 顺序类编码,无法确定
* p: 性别,奇数为男,偶数为女
* <p />
* 身份证18位编码规则:dddddd yyyymmdd xxx y
* dddddd:地区码
* yyyymmdd: 出生年月日
* xxx:顺序类编码,无法确定,奇数为男,偶数为女
* y: 校验码,该位数值可通过前17位计算获得
* <p />
* 18位号码加权因子为(从右到左) Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,1 ]
* 验证位 Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]
* 校验位计算公式:Y_P = mod( ∑(Ai×Wi),11 )
* i为身份证号码从右往左数的 2...18 位; Y_P为脚丫校验码所在校验码数组位置
*
*/
var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];// 加权因子