一些驗證
一些驗證
2011年04月01日
// 使用正則表達式,檢測 s 是否滿足模式 re
function checkExp( re, s ){
return re.test( s );
}
// 驗證是否 Email
function isEmail( strValue ){
// Email 必須是 [email protected] 等格式 或者爲空
if( isEmpty( strValue ) ) return true;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_- ])+/;
return checkExp( pattern, strValue );
}
// 驗證是否 電話
function isPhone( strValue ){
// 普通電話(0755)4477377-3301/(86755)6645798-665
// 不帶區號電話 88989899
// Call 機95952-351
// 手機130/131/133/135/136/137/138/13912345678
// 或者爲空
if( isEmpty( strValue ) ) return true;
return checkExp( /(^\(\d{3,5}\)\d{6,8}(-\d{2,8})?$)|(^\d{7,8}$)|(^\ d+-\d+$)|(^(130|131|133|135|136|137|138|139)\d{8}$) /g, strValue );
}
2011年04月01日
// 使用正則表達式,檢測 s 是否滿足模式 re
function checkExp( re, s ){
return re.test( s );
}
// 驗證是否 Email
function isEmail( strValue ){
// Email 必須是 [email protected] 等格式 或者爲空
if( isEmpty( strValue ) ) return true;
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_- ])+/;
return checkExp( pattern, strValue );
}
// 驗證是否 電話
function isPhone( strValue ){
// 普通電話(0755)4477377-3301/(86755)6645798-665
// 不帶區號電話 88989899
// Call 機95952-351
// 手機130/131/133/135/136/137/138/13912345678
// 或者爲空
if( isEmpty( strValue ) ) return true;
return checkExp( /(^\(\d{3,5}\)\d{6,8}(-\d{2,8})?$)|(^\d{7,8}$)|(^\ d+-\d+$)|(^(130|131|133|135|136|137|138|139)\d{8}$) /g, strValue );
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.