You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
11 KiB
JavaScript

11 months ago
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󳤶ȡ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkLength(tb, minLen, maxLen) {
if (tb.value.length < minLen || tb.value.length > maxLen) {
alert('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD><EFBFBD>' + minLen + ' <20><> ' + maxLen + <><D6AE>.');
}
}
/* <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
function isEmail(tb) {
if (tb.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
alert('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ʽ.');
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkMobilePhone(str) {
if (str.match(/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/) == null) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkTelephone(str) {
if (str.match(/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/) == null) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkCard(str) {
//15λ<35><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
var arg1 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
//18λ<38><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
var arg2 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/;
if (str.match(arg1) == null && str.match(arg2) == null) {
return false;
}
else {
return true;
}
}
/**************************** δ<><CEB4><EFBFBD><EFBFBD> **************************************/
/**
* 2009-10-01
* <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD> Ե
* js<EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
*/
/**************************************************************************************/
/*************************************<2A><><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>֤*****************************************/
/**************************************************************************************/
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
function checkNum(str) {
return str.match(/\D/) == null;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>ΪС<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾΪС<EFBFBD><EFBFBD>
*/
function checkDecimal(str) {
if (str.match(/^-?\d+(\.\d+)?$/g) == null) {
return false;
}
else {
return true;
}
}
/**************************************************************************************/
/*************************************<2A>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>֤*****************************************/
/**************************************************************************************/
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾΪȫ<EFBFBD><EFBFBD>Ϊ<EFBFBD>ַ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
function checkStr(str) {
if (/[^\x00-\xff]/g.test(str)) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
function checkChinese(str) {
if (escape(str).indexOf("%u") != -1) {
return true;
}
else {
return false;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkEmail(str) {
if (str.match(/[A-Za-z0-9_-]+[@](\S*)(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*)/g) == null) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQ<EFBFBD>ĸ<EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkQQ(str) {
if (str.match(/^\d{5,10}$/) == null) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkIP(str) {
var arg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
if (str.match(arg) == null) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<EFBFBD><EFBFBD>ַ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
*/
function checkURL(str) {
if (str.match(/(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i) == null) {
return false
}
else {
return true;
}
}
/**************************************************************************************/
/*************************************ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤*****************************************/
/**************************************************************************************/
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
* ע<EFBFBD><EFBFBD>˴<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>ʽ
* <EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>2007-06-05<EFBFBD><EFBFBD>
*/
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]);
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD>֤ʱ<EFBFBD><EFBFBD>(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;
}
}
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:str <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>:true <EFBFBD><EFBFBD> flase; true<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȷ
* (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;
}
}
/**************************************************************************************/
/************************************<2A><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤*************************************/
/**************************************************************************************/
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤15λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dddddd yymmdd xx p
* dddddd<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* yymmdd: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* xx: ˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ȷ<EFBFBD><EFBFBD>
* p: <EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>У<EFBFBD>ż<EFBFBD><EFBFBD>ΪŮ
* <p />
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤18λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dddddd yyyymmdd xxx y
* dddddd<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* yyyymmdd: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* xxx:˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>У<EFBFBD>ż<EFBFBD><EFBFBD>ΪŮ
* y: У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ǰ17λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <p />
* 18λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ(<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>) Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,1 ]
* <EFBFBD><EFBFBD>֤λ Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]
* У<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>㹫ʽ<EFBFBD><EFBFBD>Y_P = mod( <EFBFBD><EFBFBD>(Ai<EFBFBD><EFBFBD>Wi),11 )
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2...18 λ; Y_PΪ<EFBFBD><EFBFBD>ѾУ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
*
*/
var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; // <20><>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>
var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2]; // <20><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>֤λֵ.10<EFBFBD><EFBFBD><EFBFBD><EFBFBD>X
function IdCardValidate(idCard) {
idCard = trim(idCard.replace(/ /g, ""));
if (idCard.length == 15) {
return isValidityBrithBy15IdCard(idCard);
}
else
if (idCard.length == 18) {
var a_idCard = idCard.split(""); // <20>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>
if (isValidityBrithBy18IdCard(idCard) && isTrueValidateCodeBy18IdCard(a_idCard)) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
/**
* <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ18λʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤λ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>ȷ
* @param a_idCard <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return
*/
function isTrueValidateCodeBy18IdCard(a_idCard) {
var sum = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
if (a_idCard[17].toLowerCase() == 'x') {
a_idCard[17] = 10; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λΪx<CEAA><78><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD>滻Ϊ10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
for (var i = 0; i < 17; i++) {
sum += Wi[i] * a_idCard[i]; // <20><>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>
}
valCodePosition = sum % 11; // <20>õ<EFBFBD><C3B5><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
if (a_idCard[17] == ValideCode[valCodePosition]) {
return true;
}
else {
return false;
}
}
/**
* ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ů
* @param idCard 15/18λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return 'female'-Ů<EFBFBD><EFBFBD>'male'-<EFBFBD><EFBFBD>
*/
function maleOrFemalByIdCard(idCard) {
idCard = trim(idCard.replace(/ /g, "")); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>пո<D0BF><D5B8><EFBFBD>
if (idCard.length == 15) {
if (idCard.substring(14, 15) % 2 == 0) {
return 'female';
}
else {
return 'male';
}
}
else
if (idCard.length == 18) {
if (idCard.substring(14, 17) % 2 == 0) {
return 'female';
}
else {
return 'male';
}
}
else {
return null;
}
}
/**
* <EFBFBD><EFBFBD>֤18λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param idCard 18λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* @return
*/
function isValidityBrithBy18IdCard(idCard18) {
var year = idCard18.substring(6, 10);
var month = idCard18.substring(10, 12);
var day = idCard18.substring(12, 14);
var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>getFullYear()<29><>ȡ<EFBFBD><C8A1><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>ǧ<EFBFBD><C7A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (temp_date.getFullYear() != parseFloat(year) ||
temp_date.getMonth() != parseFloat(month) - 1 ||
temp_date.getDate() != parseFloat(day)) {
return false;
}
else {
return true;
}
}
/**
* <EFBFBD><EFBFBD>֤15λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param idCard15 15λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
* @return
*/
function isValidityBrithBy15IdCard(idCard15) {
var year = idCard15.substring(6, 8);
var month = idCard15.substring(8, 10);
var day = idCard15.substring(10, 12);
var temp_date = new Date(year, parseFloat(month) - 1, parseFloat(day));
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8BFBC>ǧ<EFBFBD><C7A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>getYear()<29><><EFBFBD><EFBFBD>
if (temp_date.getYear() != parseFloat(year) ||
temp_date.getMonth() != parseFloat(month) - 1 ||
temp_date.getDate() != parseFloat(day)) {
return false;
}
else {
return true;
}
}
//ȥ<><C8A5><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ͷβ<CDB7>ո<EFBFBD>
function trim(str) {
return str.replace(/(^\s*)|(\s*$)/g, "");
}