function isUsername(s)
{
var patrn=/([A-Za-z]{0,1}[0-9]{1,2}|[0-9]{0,1}[A-Za-z]{1,2})[A-Za-z0-9]+$/;
if (!patrn.exec(s))
{
alert("用戶名出錯![註釋:只能由數字和字母組成]");
return false;
}
return true;
}
</script>
<html>
用戶名:<input type="text" value="" onblur="isUsername(this.value)" />
</html>
function f_MobilCheck(as_SourceString)
{
if(as_SourceString.match(/^13[0-9]{9}$/g)) return true; //手機號為13開頭的11位數字
else if(as_SourceString.match(/^[0]{1}[0-9]{2,3}[2-8]{1}[0-9]{5,7}$/g)) return true; //小靈通為0開頭的3-4位的區號+不以1和9開頭的6-8位數字
return false;
}
//---------------------------------------------驗證是否合法的電子郵箱地址----合法:true---不合法:false---------
function f_EmailCheck(as_SourceString)
{
return as_SourceString.match(/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/g);
}
//----------------------------------------------驗證是否不含有非法的字符--不含有,即合法:true---不合法:false-------------
function f_StringCheck(as_SourceString)
{
//非法字符--(雙減號)/*(斜杠星號)'(單引號);(分號)"(雙引號)%(百分號)<(左尖括號)>(右尖括號)
if(as_SourceString.match(/\/\*|-{2}|[';"%<>]+/)) return false;
else return true;
}
//-------------------------------驗證字符串長度是否符合要求---0-為空,1-為小於下限,2-為大於上限,3-符合要求---
function f_StringLenCheck(as_SourceString, low_Length, up_Length)
{
//字符串長度,單字節計1,雙字節計和漢字等計2
as_SourceString = as_SourceString.replace(/[^\x00-\xff]/g,"aa");
if(as_SourceString.length == 0) return 0;
else if(as_SourceString.length < low_Length) return 1;
else if(as_SourceString.length > up_Length) return 2;
else return 3;
}
//---------------------------------------------驗證是否全部是數字且不以0開頭----合法:true---不合法:false---------
function f_NumericCheck(as_SourceString)
{
return as_SourceString.match(/^[1-9]{1}\d*$/g);
}
//---------------------------------------------驗證是否全部是數字可以0開頭----合法:true---不合法:false---------
function f_NumericCheckAll(as_SourceString)
{
return as_SourceString.match(/^[0-9]{1}\d*$/g);
}
//---------------------------------------------驗證是否為標準的電話號碼----合法:true---不合法:false---------
function f_MobilCheck(as_SourceString)
{
if(as_SourceString.match(/^13[0-9]{9}$/g)) return true; //手機號為13開頭的11位數字
else if(as_SourceString.match(/^[0]{1}[0-9]{2,3}[2-8]{1}[0-9]{5,7}$/g)) return true; //小靈通為0開頭的3-4位的區號+不以1和9開頭的6-8位數字
return false;
}
//---------------------------------------------驗證是否為標準的身份證號碼----合法:true---不合法:false---------
function f_IDCardCheck(as_SourceString)
{
return as_SourceString.match(/^[0-9]{6}[1-2]{1}[0-9]{3}[0-1]{1}[0-9]{1}[0-3]{1}[0-9]{1}[0-9]{3}[xX0-9]{1}$/g);
}
//----------------------------------------------驗證短日期格式----------------------------------------------------
function f_DateShortCheck(as_SourceString)//2000-1-1或2000-01-01
{
return as_SourceString.match(/^([1-2]{1})([0-9]{3})-(0?[1-9]|10|11|12)-(0?[1-9]|[1-2][0-9]|30|31)$/g);
}
{
if(as_SourceString.match(/^13[0-9]{9}$/g)) return true; //手機號為13開頭的11位數字
else if(as_SourceString.match(/^[0]{1}[0-9]{2,3}[2-8]{1}[0-9]{5,7}$/g)) return true; //小靈通為0開頭的3-4位的區號+不以1和9開頭的6-8位數字
return false;
}