// 身份證字號
function checkID(string) {
re = /^[A-Z]\d{9}$/;
if (re.test(string))
return true;
}
// 信用卡號
function checkCreditCard(string) {
re = /^\d{4}-\d{4}-\d{4}-\d{4}$/;
// re = /^(\d{4}-){3}\d{4}$/;
if (re.test(string))
return true;
}
// 英文名稱
function checkEnglishName(string) {
re1 = /^[A-Za-z\-]+\s+[A-Za-z\-]+$/;
re2 = /^[A-Za-z\-]+\s+[A-Za-z\-]+\s+[A-Za-z\-]+$/;
if (re1.test(string) || re2.test(string))
return true;
}
// Email
function checkEmail(string) {
re = /^.+@.+\..{2,3}$/;
if (re.test(string))
return true;
}
// 數字
function checkNumber(string) {
re = /^\d+$/;
if (re.test(string))
return true;
}
// TextBox
function checkValue(aTextID)
{
re = /\S/;
var oText = document.all[aTextID];
var sVal = Trim(oText.value);
if(!re.test(sVal)){
try{
alert("[" + oText.title + "]" + " 必需填寫!")
event.returnValue = false;
oText.focus();
return false;
}
catch (e){
//alert(e.description);
}
}
return true;
}
- Nov 18 Tue 2008 14:24
[javascript] 用RE(正規化表示法)做資料驗證
全站熱搜
留言列表
發表留言