验证台湾同胞身份证信息
Validation.add('validate-identify', '請输入有效的身份證信息', function (value) {
//建立字母分數陣列(A~Z)
var city = new Array(
1, 10, 19, 28, 37, 46, 55, 64, 39, 73, 82, 2, 11,
20, 48, 29, 38, 47, 56, 65, 74, 83, 21, 3, 12, 30
)
var id = value.toUpperCase();
// 使用「正規表達式」檢驗格式
if (id.search(/^[A-Z](1|2)\d{8}$/i) == -1) {
return false;
} else {
var id = id.split('');
//計算總分
var total = city[id[0].charCodeAt(0) - 65];
for (var i = 1; i <= 8; i++) {
total += eval(id[i]) * (9 - i);
}
//補上檢查碼(最後一碼)
total += eval(id[9]);
//檢查比對碼(餘數應為0);
return ((total % 10 == 0));
}
});
function checkTwID($id){
//建立字母分數陣列
$city = array('A'=>1,'I'=>39,'O'=>48,'B'=>10,'C'=>19,'D'=>28,
'E'=>37,'F'=>46,'G'=>55,'H'=>64,'J'=>73,'K'=>82,
'L'=>2,'M'=>11,'N'=>20,'P'=>29,'Q'=>38,'R'=>47,
'S'=>56,'T'=>65,'U'=>74,'V'=>83,'W'=>21,'X'=>3,
'Y'=>12,'Z'=>30);
//檢查身份字號
if (!preg_match("/[A-Z][1-2]\d{8}/",$id = strtoupper($id))){
return false;
} else {
//計算總分
$total = $city[$id[0]];
for($i=1;$i<=8;$i++){
$total += $id[$i] * (9 - $i);
}
//補上檢查碼(最後一碼)
$total += $id[9];
//檢查比對碼(餘數應為0);
return (($total%10 === 0 ));
}
}