[java/VB script] JavaScript常用正則表達式函數



[java/VB script] JavaScript常用正則表達式函數

教程由JAVA中文網整理校對發佈(javaweb.cc)

/**
* 驗證普通字串,只要字串中不包含特殊字符即可
*/
function checkTextDataForNORMAL(strValue)
{
// 特殊字符驗證格式
var regTextChar = /([\*\"\'<>\/])+/ ;
return !regTextChar.test(strValue);
}

/**
* 驗證整數,包含正整數和負整數
*/
function checkTextDataForINTEGER(strValue)
{
var regTextInteger = /^(-|\+)?(\d)*$/;
return regTextInteger.test(strValue);
}

/**
* 檢查是否為正整數
*/
function isUnsignedInteger(strInteger)
{
var newPar=/^\d+$/
return newPar.test(strInteger);
}

function checkMoney(strValue, strUnit)
{
var testMoney = eval("/^\\d+(\\.\\d{0," + (strUnit.length -1) + "})?$/");
return testMoney.test(strValue);
}

/**
* 驗證浮點數
*/
function checkTextDataForFLOAT(strValue)
{
var regTextFloat = /^(-)?(\d)*(\.)?(\d)*$/;
return regTextFloat.test(strValue);
}

/**
* 驗證數字
*/
function checkTextDataForNUMBER(strValue)
{
var regTextNumber = /^(\d)*$/;
return regTextNumber.test(strValue);
}

/**
* 驗證英文字母,不區分大小寫
*/
function checkTextDataForENGLISH(strValue)
{
var regTextEnglish = /^[a-zA-Z]*$/;
return regTextEnglish.test(strValue);
}

/**
* 驗證大寫英文字母
*/
function checkTextDataForENGLISHUCASE(strValue)
{
var regTextEnglishUCase = /^[A-Z]*$/;
return regTextEnglishUCase.test(strValue);
}

/**
* 驗證小寫英文字母
*/
function checkTextDataForENGLISHLCASE(strValue)
{
var regTextEnglishLCase = /^[a-z]*$/;
return regTextEnglishLCase.test(strValue);
}

/** JavaScript教程:http://www.javaweb.cc/language/javascript/
* 驗證英文字母和數字,不區分大小寫
*/
function checkTextDataForENGLISHNUMBER(strValue)
{
var regTextEnglishNumber = /^[a-zA-Z0-9]*$/;
return regTextEnglishNumber.test(strValue);
}

/**
* 驗證時間
*/
function checkTextDataForTIME(strValue)
{
var regTextTime = /^(\d+):(\d{1,2}):(\d{1,2})$/;
return regTextTime.test(strValue);
}

/**
* 驗證電話號碼
*/
function checkTextDataForPHONE(strValue)
{
var regTextPhone = /^(\(\d+\))*(\d)+(-(\d)+)*$/;
return regTextPhone.test(strValue);
}

/**
* 驗證EMail
*/
function checkTextDataForEMAIL(strValue)
{
var regTextEmail = /^[\w-]+@[\w-]+(\.(\w)+)*(\.(\w){2,3})$/;
return regTextEmail.test(strValue);
}

/**
* 驗證URL
*/
function checkTextDataForURL(strValue)
{
var regTextUrl = /^(file|http|https|ftp|mms|telnet|news|wais|mailto):\/\/(.+)$/;
return regTextUrl.test(strValue);
}

/**
* 驗證郵政編碼
*/
function checkTextDataForPOST(strValue)
{
var regTextPost = /^(\d){6}$/;
return regTextPost.test(strValue);
}


JavaScript常用正則表達式函數(本教程僅供研究和學習,不代表JAVA中文網觀點)
本篇文章鏈接地址:http://www.javaweb.cc/language/javascript/292245.shtml
如需轉載請註明出自JAVA中文網:http://www.javaweb.cc/