/***************************************************
* EO_JSLib
* javascript正則表達式檢驗
*******************************************************/
//校驗是否全由數字組成
function isDigit(s)
{
var patrn=/^[
if (!patrn
return true
}
//校驗登錄名
function isRegisterUserName(s)
{
var patrn=/^[a
if (!patrn
return true
}
//校驗用戶姓名
function isTrueName(s)
{
var patrn=/^[a
if (!patrn
return true
}
//校驗密碼
function isPasswd(s)
{
var patrn=/^(\w){
if (!patrn
return true
}
//校驗普通電話
function isTel(s)
{
//var patrn=/^[+]{
var patrn=/^[+]{
if (!patrn
return true
}
//校驗手機號碼
function isMobil(s)
{
var patrn=/^[+]{
if (!patrn
return true
}
//校驗郵政編碼
function isPostalCode(s)
{
//var patrn=/^[a
var patrn=/^[a
if (!patrn
return true
}
//校驗搜索關鍵字
function isSearch(s)
{
var patrn=/^[^`~!@#$%^&*()+=|\\\][\]\{\}:;\
if (!patrn
return true
}
function isIP(s) //by zergling
{
var patrn=/^[
if (!patrn
return true
}
/*************************************************
* FUNCTION: isBetween
* PARAMETERS: val AS any value
* lo AS Lower limit to check
* hi AS Higher limit to check
* CALLS: NOTHING
* RETURNS: TRUE if val is between lo and hi both inclusive
***************************************************/
function isBetween (val
if ((val < lo) || (val > hi)) { return(false); }
else { return(true); }
}
/************************************************
* FUNCTION: isDate checks a valid date
* PARAMETERS: theStr AS String
* CALLS: isBetween
* RETURNS: TRUE if theStr is a valid date otherwise false
*************************************************/
function isDate (theStr) {
var the
var the
if (the
else {
var y = theStr
var m = theStr
var d = theStr
var maxDays =
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y
else if (!isBetween (m
else if (m==
else if (m==
if (y %
else if (y %
else maxDays =
}
if (isBetween(d
else { return(true); }
}
}
/**********************************************
* FUNCTION: isEuDate checks a valid date in British format
* PARAMETERS: theStr AS String
* CALLS: isBetween
* RETURNS: TRUE if theStr is a valid date otherwise false
*************************************************/
function isEuDate (theStr) {
if (isBetween(theStr
else {
var the
var the
if (the
else {
var m = theStr
var d = theStr
var y = theStr
var maxDays =
if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
return(false); }
else if (y
else if (isBetween (m
else if (m==
else if (m==
if (y %
else if (y %
else maxDays =
}
if (isBetween(d
else { return(true); }
}
}
}
/**************************************************
* FUNCTION: Compare Date! Which is the latest!
* PARAMETERS: lessDate
* CALLS: isDate
* RETURNS: TRUE if lessDate<moreDate
****************************************************/
function isComdate (lessDate
{
if (!isDate(lessDate)) { return(false);}
if (!isDate(moreDate)) { return(false);}
var less
var less
var more
var more
var lessy = lessDate
var lessm = lessDate
var lessd = lessDate
var morey = moreDate
var morem = moreDate
var mored = moreDate
var Date
var Date
if (Date
return(true);
}
/**********************************************
* FUNCTION isEmpty checks if the parameter is empty or null
* PARAMETER str AS String
*************************************************/
function isEmpty (str) {
if ((str==null)||(str
else return(false);
}
/***********************************************
* FUNCTION: isInt
* PARAMETER: theStr AS String
* RETURNS: TRUE if the passed parameter is an integer
* CALLS: isDigit
***************************************************/
function isInt (theStr) {
var flag = true;
if (isEmpty(theStr)) { flag=false; }
else
{ for (var i=
if (isDigit(theStr
flag = false; break;
}
}
}
return(flag);
}
/*****************************************************
* FUNCTION: isReal
* PARAMETER: heStr AS String
decLen AS Integer (how many digits after period)
* RETURNS: TRUE if theStr is a float
* CALLS: isInt
*******************************************************/
function isReal (theStr
var dot
var dot
var OK = true;
if (isEmpty(theStr)) return false;
if (dot
if (!isInt(theStr)) return(false);
else return(true);
}
else if (dot
else if (dot
else {
var intPart = theStr
var decPart = theStr
if (decPart
else if (!isInt(intPart) || !isInt(decPart)) return (false);
else if (isEmpty(decPart)) return (false);
else return(true);
}
}
/*****************************************************
* FUNCTION: isEmail
* PARAMETER: String (Email Address)
* RETURNS: TRUE if the String is a valid Email address
* FALSE if the passed string is not a valid Email Address
* EMAIL FORMAT: AnyName@EmailServer e
* @ sign can appear only once in the email address
*******************************************************/
function isEmail (theStr) {
var atIndex = theStr
var dotIndex = theStr
var flag = true;
theSub = theStr
if ((atIndex <
{ return(false); }
else { return(true); }
}
/********************************************************
* FUNCTION: newWindow
* PARAMETERS: doc
hite
wide
bars
resize
* CALLS: NONE
* RETURNS: New window instance
*************************************************************/
function newWindow (doc
var winNew=
var opt=
opt+=(
opt+=(
opt+=(
opt+=(
winHandle=window
return;
}
/***********************************************************
* FUNCTION: DecimalFormat
* PARAMETERS: paramValue
* CALLS: NONE
* RETURNS: Formated string
***************************************************************/
function DecimalFormat (paramValue) {
var intPart = parseInt(paramValue);
var decPart =parseFloat(paramValue)
str =
if ((decPart ==
else str += (intPart + decPart);
return (str);
}
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25473.html