// 是否為整數
function IsInteger(str,title)
{
if(str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
var tmp = parseInt(str.value)
if (isNaN(tmp))
{
alert(title+":必須輸入整數!");
str.focus();
return false
}
else if (tmp.toString() ==str.value)
{
return true
}
else
{
alert(title+":必須輸入整數!");
str.focus();
return false
}
}
//是否為空值 (欄位未填)
function IsFill(str,title)
{
if (str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
return true;
}
//是否為中文
function IsChinese(str,title)
{
if(str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
for( i = 0; i < str.value.length; i ++ )
{
if (str.value.charCodeAt(i)>10000)
{
}
else
{
alert(title+":只能輸入中文!");
str.focus();
return false;
}
}
}
//是否為英文字串
function IsEnglishWord(str,title)
{
if(str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
var checkEN;
var i;
var j;
for( i = 0; i < str.value.length; i ++ )
{
checkEN = str.value.charCodeAt(i);
if ((checkEN >= 65 && checkEN <= 90) || (checkEN >= 97 && checkEN <= 122))
{
}
else
{
alert(title+":中只能包含26個字母");
str.focus();
return false;
}
}
return true;
}
//是否為英數字
function IsEwordAndNumberAndOther(str,title)
{
if(str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
var checkEN;
var i;
var j;
for( i = 0; i < str.value.length; i ++ )
{
checkEN = str.value.charCodeAt(i);
if ((checkEN >= 48 && checkEN <= 57) || (checkEN >= 65 && checkEN <= 90) || (checkEN >= 97 && checkEN <= 122))
{
}
else
{
alert(title+":只能包含數字和字母");
str.focus();
return false;
}
}
return true;
}
//是否為數字
function IsNumber(str,title)
{
if(str.value.length == 0)
{
alert(title+":不能為空!");
str.focus();
return false;
}
var Letters = "1234567890.";
var i;
var c;
for( i = 0; i < str.value.length; i ++ )
{
c = str.value.charAt(i);
if (Letters.indexOf(c)<0)
{
alert(title+":必須為數字");
str.focus();
return false;
}
}
return true;
}
//是否為電子郵件格式字串
function IsEMailFormat(str,title)
{
var emailStr=str.value;
var emailPat=/^(.+)@(.+)$/;
var matchArray=emailStr.match(emailPat);
if (matchArray==null)
{
alert(title+":電子郵件地址必須包括@和.");
str.focus();
return false;
}
return true;
}
/*這是鍵盤事件
//使用戶只能輸入數字
function onlydigital()
{
var iCode=event.keyCode;
//alert(iCode);
if(((iCode<48)||((iCode>57)&&(iCode<96))||iCode>105)&&((iCode!=8)&&(iCode!=109)&&(iCode!=189)&&(iCode!=9)
&&(iCode!=229)&&(iCode!=13)&&(iCode!=110)&&(iCode!=190)&&(iCode!=46)&&(iCode!=27))&&((iCode<37)||(iCode>40)))
{
event.returnValue=false;
}
}
/*附:?的???字190,110:小??,13:回?,109,189:-,37:左箭?,38:下箭?,39:右箭?,40:上箭?,8:退格 48-57:大???字,
96-105:小???字,9:TAB?,46:?除*/
//日期?型:使用?只能?入日期所使用的字符,即?字,"-"符?。
/*
function fnTrapAlpha()
{
var iCode=event.keyCode;
if(((iCode<48)||((iCode>57)&&(iCode<96))||iCode>105)&&((iCode!=8)&&(iCode!=9)&&(iCode!=190)&&(iCode!=46)
&&(iCode!=109)&&(iCode!=110)&&(iCode!=189)&&(iCode!=37)&&(iCode!=39)&&(iCode!=229)&&(iCode!=27)))
{
event.returnValue=false; //?句?使?足以上?件的??入??效。
}
}
*/