The editor has compiled a lot of examples of regular expressions commonly used in JavaScript before, and they are all used by themselves. Now I will share them with you.
The code copy is as follows:
/**
* Get the byte length of the string
*/
function strlen(str)
{
var i;
var len;
len = 0;
for (i=0;i<str.length;i++)
{
if (str.charCodeAt(i)>255) len+=2; else len++;
}
return len;
}
/*
* Determine whether it is a number, return true, otherwise return false
*/
function f_check_number(obj)
{
if (/^/d+$/.test(obj.value))
{
return true;
}
else
{
f_alert(obj,"Please enter a number");
return false;
}
}
/*
* To determine whether it is a natural number, return true, otherwise return false
*/
function f_check_naturalnumber(obj)
{
var s = obj.value;
if (/^[0-9]+$/.test( s ) && (s > 0))
{
return true;
}
else
{
f_alert(obj,"Please enter a natural number");
return false;
}
}
/*
* To determine whether it is an integer, return true, otherwise return false
*/
function f_check_integer(obj)
{
if (/^(/+|-)?/d+$/.test( obj.value ))
{
return true;
}
else
{
f_alert(obj,"Please enter an integer");
return false;
}
}
/*
* To determine whether it is a real number, return true, otherwise return false
*/
function f_check_float(obj)
{
if (/^(/+|-)?/d+($|/./d+$)/.test( obj.value ))
{
return true;
}
else
{
f_alert(obj,"Please enter real number");
return false;
}
}
/*
* Check the length and accuracy of the number
*/
function f_check_double(obj){
var numReg;
var value = obj.value;
var strValueTemp, strInt, strDec;
var dtype = obj.eos_datatype;
var pos_dtype = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")).split(",");
var len = pos_dtype[0], prec = pos_dtype[1];
try
{
numReg =/[/-]/;
strValueTemp = value.replace(numReg, "");
numReg =/[/+]/;
strValueTemp = strValueTemp.replace(numReg, "");
//Integer
if(prec==0){
numReg =/[/.]/;
if(numReg.test(value) == true){
f_alert(obj, "The input must be of integer type");
return false;
}
}
if(strValueTemp.indexOf(".") < 0 ){
if(strValueTemp.length >( len - prec)){
f_alert(obj, "Integer bits cannot exceed"+ (len - prec) +"bits");
return false;
}
}else{
strInt = strValueTemp.substr( 0, strValueTemp.indexOf(".") );
if(strInt.length >( len - prec)){
f_alert(obj, "Integer bits cannot exceed"+ (len - prec) +"bits");
return false;
}
strDec = strValueTemp.substr( (strValueTemp.indexOf(".")+1), strValueTemp.length );
if(strDec.length > prec){
f_alert(obj, "The decimal digit cannot exceed "+ prec + "bits");
return false;
}
}
return true;
}catch(e){
alert("in f_check_double = " + e);
return false;
}
}
/*
* Check the minimum maximum value of the number
* Return to bool
*/
function f_check_interval(obj)
{
var value = parseFloat(obj.value);
var dtype = obj.eos_datatype;
var pos_dtype = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")).split(",");
var minLimit = pos_dtype[0];
var maxLimit = pos_dtype[1];
var minVal = parseFloat(pos_dtype[0]);
var maxVal = parseFloat(pos_dtype[1]);
if(isNaN(value))
{
f_alert(obj, "value must be a number");
return false;
}
if((isNaN(minVal) && (minLimit != "-")) || (isNaN(maxVal) && (maxLimit != "+"))))
{
f_alert(obj, "The boundary value must be a number or -, +");
return false;
}
if(minLimit == "-" && !isNaN(maxVal))
{
if(value > maxVal)
{
f_alert(obj, "value cannot exceed" + maxVal);
return false;
}
}
if(!isNaN(minVal) && maxLimit == "+")
{
if(value < minVal)
{
f_alert(obj, "value cannot be less than" + minVal);
return false;
}
}
if(!isNaN(minVal) && !isNaN(maxVal))
{
if(minVal > maxVal)
{
f_alert(obj, "start value" + minVal + "cannot be greater than terminating value" + maxVal);
}else
{
if(!(value <= maxVal && value >= minVal))
{
f_alert(obj, "value should be between " + minVal + " and " + maxVal + "");
return false;
}
}
}
return true;
}
/*
Purpose: Check whether the input string is composed of only Chinese characters
If true is returned by verification, otherwise false
*/
function f_check_zh(obj){
if (/^[/u4e00-/u9fa5]+$/.test(obj.value)) {
return true;
}
f_alert(obj,"Please enter Chinese characters");
return false;
}
/*
* Determine whether it is a lowercase English letter. If it is yes, it will return true, otherwise it will return false
*/
function f_check_lowercase(obj)
{
if (/^[az]+$/.test( obj.value ))
{
return true;
}
f_alert(obj,"Please enter lowercase English letters");
return false;
}
/*
* Determine whether it is capital English letters, return true, otherwise return false
*/
function f_check_uppercase(obj)
{
if (/^[AZ]+$/.test( obj.value ))
{
return true;
}
f_alert(obj,"Please enter capital letters");
return false;
}
/*
* To determine whether it is an English letter, return true, otherwise return false
*/
function f_check_letter(obj)
{
if (/^[A-Za-z]+$/.test( obj.value ))
{
return true;
}
f_alert(obj,"Please enter English letters");
return false;
}
/*
Purpose: Check whether the input string is composed of only Chinese characters, letters, and numbers.
enter:
value: string
return:
If true is returned by verification, otherwise false
*/
function f_check_ZhOrNumOrLett(obj){ //Judge whether it is composed of Chinese characters, letters, and numbers
var regu = "^[0-9a-zA-Z/u4e00-/u9fa5]+$";
var re = new RegExp(regu);
if (re.test( obj.value )) {
return true;
}
f_alert(obj,"Please enter Chinese characters, letters or numbers");
return false;
}
/*
Purpose: Verify the format of the IP address
Enter: strIP:ip address
Return: if true is returned by verification, otherwise false is returned;
*/
function f_check_IP(obj)
{
var re=/^(/d+)/.(/d+)/.(/d+)/.(/d+)$/; // Regular expression matching IP address
if(re.test( obj.value ))
{
if( RegExp.$1<=255 && RegExp.$1>=0
&&RegExp.$2<=255 && RegExp.$2>=0
&&RegExp.$3<=255 && RegExp.$3>=0
&&RegExp.$4<=255 && RegExp.$4>=0 )
{
return true;
}
}
f_alert(obj,"Please enter the legal computer IP address");
return false;
}
/*
Purpose: Check whether the value of the input object meets the port number format
Input: str Entered string
Return: if true is returned by verification, otherwise false
*/
function f_check_port(obj)
{
if(!f_check_number(obj))
return false;
if(obj.value < 65536)
return true;
f_alert(obj,"Please enter the legal computer IP address and port number");
return false;
}
/*
Purpose: Check whether the value of the input object meets the URL format
Input: str Entered string
Return: if true is returned by verification, otherwise false
*/
function f_check_URL(obj){
var myReg = /^((http:[/][/])?/w+([.]/w+|[/]/w*)*)?$/;
if(myReg.test( obj.value )) return true;
f_alert(obj,"Please enter the legal web address");
return false;
}
/*
Purpose: Check whether the value of the input object conforms to the E-Mail format
Input: str Entered string
Return: if true is returned by verification, otherwise false
*/
function f_check_email(obj){
var myReg = /^([-_A-Za-z0-9/.]+)@([_A-Za-z0-9]+/.)+[A-Za-z0-9]{2,3}$/;
if(myReg.test( obj.value )) return true;
f_alert(obj,"Please enter a legal email address");
return false;
}
/*
Requirements: 1. The mobile phone number is 11 or 12 digits. If it is 12 digits, then the first digit is 0
2. The first and second digits of the 11-digit mobile phone number are "13"
Third, the second and third digits of the 12-digit mobile phone number are "13"
Purpose: Check whether the mobile phone number is entered correctly
enter:
s: string
return:
If true is returned by verification, otherwise false
*/
function f_check_mobile(obj){
var regu =/(^[1][3][0-9]{9}$)|(^0[1][3][0-9]{9}$)/;
var re = new RegExp(regu);
if (re.test( obj.value )) {
return true;
}
f_alert(obj,"Please enter the correct mobile phone number");
return false;
}
/*
Requirements: 1. Phone number consists of numbers, "(", ")" and "-"
2. Phone numbers are 3 to 8 digits
3. If the phone number contains an area code, then the area code is three or four digits.
4. Area codes are separated from other parts by "(", ")" or "-"
Purpose: Check whether the entered phone number is in correct format
enter:
strPhone: string
return:
If true is returned by verification, otherwise false
*/
function f_check_phone(obj)
{
var regu =/(^([0][1-9]{2,3}[-])?/d{3,8}(-/d{1,6})?$)|(^/([0][1-9]{2,3}/)/d{3,8}(/(/d{1,6}/))?$)|(^/d{3,8}$)/;
var re = new RegExp(regu);
if (re.test( obj.value )) {
return true;
}
f_alert(obj,"Please enter the correct phone number");
return false;
}
/* Determine whether it is a postal code*/
function f_check_zipcode(obj)
{
if(!f_check_number(obj))
return false;
if(obj.value.length!=6)
{
f_alert(obj,"The length of the postal code must be 6 digits");
return false;
}
return true;
}
/*
User ID, which can be a combination of numbers, letters, and underscores.
The first character cannot be a number, and the total length cannot exceed 20.
*/
function f_check_userID(obj)
{
var userID = obj.value;
if(userID.length > 20)
{
f_alert(obj,"ID length cannot be greater than 20");
return false;
}
if(!isNaN(userID.charAt(0)))
{
f_alert(obj,"The first character of ID cannot be a number");
return false;
}
if(!/^/w{1,20}$/.test(userID))
{
f_alert(obj,"ID can only be composed of numbers, letters, and underscores");
return false;
}
return true;
}
/*
Function: Verify whether the ID number is valid
Prompt message: Not entered or the ID number is incorrect!
Use: f_check_IDno(obj)
Return: bool
*/
function f_check_IDno(obj)
{
var aCity={11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner Mongolia",21:"Liaoning",22:"Jilin",23:"Heilongjiang",31:"Shanghai",32:"Jiangsu",33:"Zhejiang",34:"Anhui",35:"Fujian",36:"Jiangxi",37:"Shandong",41:"Henan",42:"Hubei", 43:"Hunan",44:"Guangdong",45:"Guangxi",46:"Hainan",50:"Chongqing",51:"Sichuan",52:"Guizhou",53:"Yunnan",54:"Tibet",61:"Shaanxi",62:"Gansu",63:"Qinghai",64:"Ningxia",65:"Xinjiang",71:"Taiwan",81:"Hong Kong",82:"Macao",91:"Foreign"};
var iSum = 0;
var info = "";
var strIDno = obj.value;
var idCardLength = strIDno.length;
if(!/^/d{17}(/d|x)$/i.test(strIDno)&&!/^/d{15}$/i.test(strIDno))
{
f_alert(obj,"illegal ID number");
return false;
}
//In the subsequent operation, x is equivalent to the number 10, so it is converted to a
strIDno = strIDno.replace(/x$/i,"a");
if(aCity[parseInt(strIDno.substr(0,2))]==null)
{
f_alert(obj,"illegal area");
return false;
}
if (idCardLength==18)
{
sBirthday=strIDno.substr(6,4)+"-"+Number(strIDno.substr(10,2))+"-"+Number(strIDno.substr(12,2));
var d = new Date(sBirthday.replace(/-/g,"/"))
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))
{
f_alert(obj,"illegal birthday");
return false;
}
for(var i = 17;i>=0;i --)
iSum += (Math.pow(2,i) % 11) * parseInt(strIDno.charAt(17 - i),11);
if(iSum%11!=1)
{
f_alert(obj,"illegal ID number");
return false;
}
}
else if (idCardLength==15)
{
sBirthday = "19" + strIDno.substr(6,2) + "-" + Number(strIDno.substr(8,2)) + "-" + Number(strIDno.substr(10,2));
var d = new Date(sBirthday.replace(/-/g,"/"))
var dd = d.getFullYear().toString() + "-" + (d.getMonth()+1) + "-" + d.getDate();
if(sBirthday != dd)
{
f_alert(obj,"illegal birthday");
return false;
}
}
return true;
}
/*
* Determine whether the string meets the specified regular expression
*/
function f_check_formatStr(obj)
{
var str = obj.value;
var dtype = obj.eos_datatype;
var regu = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //Specified regular expression
var re = new RegExp(regu);
if(re.test(str))
return true;
f_alert(obj , "does not meet the specified regular expression requirements");
return false;
}
/*
Function: determine whether it is a date (format: yyyy year MM month dd date, yyyy-MM-dd, yyyyy/MM/dd, yyyyMMdd)
Tip: The date not entered or entered is incorrect in format!
Use: f_check_date(obj)
Return: bool
*/
function f_check_date(obj)
{
var date = Trim(obj.value);
var dtype = obj.eos_datatype;
var format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //Date format
var year,month,day,datePat,matchArray;
if(/^(y{4})(-|//)(M{1,2})/2(d{1,2})$/.test(format))
datePat = /^(/d{4})(-|//)(/d{1,2})/2(/d{1,2})$/;
else if(/^(y{4})(year)(M{1,2})(month)(d{1,2})(d{1,2})(d)$/.test(format))
datePat = /^(/d{4})year(/d{1,2})month(/d{1,2})day$/;
else if(format=="yyyyMMdd")
datePat = /^(/d{4})(/d{2})(/d{2})$/;
else
{
f_alert(obj,"date format is incorrect");
return false;
}
matchArray = date.match(datePat);
if(matchArray == null)
{
f_alert(obj,"The date length is incorrect, or there are non-numeric symbols in the date");
return false;
}
if(/^(y{4})(-|//)(M{1,2})/2(d{1,2})$/.test(format))
{
year = matchArray[1];
month = matchArray[3];
day = matchArray[4];
} else
{
year = matchArray[1];
month = matchArray[2];
day = matchArray[3];
}
if (month < 1 || month > 12)
{
f_alert(obj,"month should be an integer from 1 to 12");
return false;
}
if (day < 1 || day > 31)
{
f_alert(obj,"The number of days per month should be an integer from 1 to 31");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31)
{
f_alert(obj,"The month does not exist on the 31st");
return false;
}
if (month==2)
{
var isleap=(year % 4==0 && (year % 100 !=0 || year % 400==0));
if (day>29)
{
f_alert(obj,"February has up to 29 days");
return false;
}
if ((day==29) && (!isleap))
{
f_alert(obj,"There are only 29 days in leap year");
return false;
}
}
return true;
}
/*
Function: The format of verification is yyyy year MM month dd day HH hour mm minutes ss seconds, yyyy-MM-dd HH:mm:ss,yyyyy/MM/dd HH:mm:ss,yyyyMMddHHmmss
Prompt message: Time format not entered or entered is incorrect
Use: f_check_time(obj)
Return: bool
*/
function f_check_time(obj)
{
var time = Trim(obj.value);
var dtype = obj.eos_datatype;
var format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //Date format
var datePat,matchArray,year,month,day,hour,minute,second;
if(/^(y{4})(-|//)(M{1,2})/2(d{1,2}) (HH:mm:ss)$/.test(format))
datePat = /^(/d{4})(-|//)(/d{1,2})/2(/d{1,2}) (/d{1,2}):(/d{1,2}):(/d{1,2}):(/d{1,2})$/;
else if(/^(y{4})(year)(M{1,2})(month)(d{1,2})(d{1,2})(d)(HH hour, mm minute, ss seconds)$/.test(format))
datePat = /^(/d{4})year(/d{1,2})month(/d{1,2})day(/d{1,2})hour(/d{1,2})minute(/d{1,2})seconds$/;
else if(format == "yyyyMMddHHmmss")
datePat = /^(/d{4})(/d{2})(/d{2})(/d{2})(/d{2})(/d{2})(/d{2})(/d{2})$/;
else
{
f_alert(obj,"date format is incorrect");
return false;
}
matchArray = time.match(datePat);
if(matchArray == null)
{
f_alert(obj,"The date length is incorrect, or there are non-numeric symbols in the date");
return false;
}
if(/^(y{4})(-|//)(M{1,2})/2(d{1,2}) (HH:mm:ss)$/.test(format))
{
year = matchArray[1];
month = matchArray[3];
day = matchArray[4];
hour = matchArray[5];
minute = matchArray[6];
second = matchArray[7];
} else
{
year = matchArray[1];
month = matchArray[2];
day = matchArray[3];
hour = matchArray[4];
minute = matchArray[5];
second = matchArray[6];
}
if (month < 1 || month > 12)
{
f_alert(obj,"month should be an integer from 1 to 12");
return false;
}
if (day < 1 || day > 31)
{
f_alert(obj,"The number of days per month should be an integer from 1 to 31");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31)
{
f_alert(obj,"The month does not exist on the 31st");
return false;
}
if (month==2)
{
var isleap=(year % 4==0 && (year % 100 !=0 || year % 400==0));
if (day>29)
{
f_alert(obj,"February has up to 29 days");
return false;
}
if ((day==29) && (!isleap))
{
f_alert(obj,"There are only 29 days in leap year");
return false;
}
}
if(hour<0 || hour>23)
{
f_alert(obj,"Hours should be integers from 0 to 23");
return false;
}
if(minute<0 || minute>59)
{
f_alert(obj,"score should be an integer from 0 to 59");
return false;
}
if(second<0 || second>59)
{
f_alert(obj,"seconds should be integers from 0 to 59");
return false;
}
return true;
}
/*Judge whether the current object is visible*/
function isVisible(obj){
var visAtt,disAtt;
try{
disAtt=obj.style.display;
visAtt=obj.style.visibility;
}catch(e){}
if(disAtt=="none" || visAtt=="hidden")
return false;
return true;
}
/*Judge whether the current object and its parent object are visible*/
function checkPrVis(obj){
var pr=obj.parentNode;
do{
if(pr == undefined || pr == "undefined") return true;
else{
if(!isVisible(pr)) return false;
}
}while(pr=pr.parentNode);
return true;
}
/* A warning dialog box pops up. After the user clicks to confirm, place the cursor on the error text box, and selects the original input content. */
function f_alert(obj,acertInfo)
{
var caption = obj.getAttribute("eos_displayname");
if(caption == null)
caption = "";
alert(caption + ":" + alertInfo + "!");
obj.select();
if(isVisible(obj) && checkPrVis(obj))
obj.focus();
}
/**
* Check whether the string is empty
*/
function isnull(str)
{
var i;
if(str.length == 0)
return true;
for (i=0;i<str.length;i++)
{
if (str.charAt(i)!=' ')
return false;
}
return true;
}
/**
* Check whether the input of the specified text box is legal.
* If the user inputs something wrong, a prompt dialog box will pop up.
* At the same time, focus on the text box and in front of the text box
* A warning icon will appear (it will be automatically removed after input correctly).
*/
function checkInput(object)
{
var image;
var i;
var length;
if(object.eos_maxsize + "" != "undefined") length = object.eos_maxsize;
else length = 0;
if (object.eos_isnull=="true" && isnull(object.value)) return true;
/* Length check*/
if(length != 0 && strlen(object.value) > parseInt(length)) {
f_alert(object, "maximum length exceeded" + length);
return false;
}
/* Data type verification*/
else {
if (object.eos_datatype + "" != "undefined")
{
var dtype = object.eos_datatype;
var objName = object.name;
//If the type name is followed by brackets, the string before the brackets is regarded as the check type
if(dtype.indexOf("(") != -1)
dtype = dtype.substring(0,dtype.indexOf("("));
//Check according to the verification type of page elements
try{
if(eval("f_check_" + dtype + "(object)") != true)
return false;
}catch(e){return true;}
/* If the first half of name exists in form, and there are both form fields ending with "min" and "max",
Then it is considered to be query by interval. That is, the value of the form field ending "min" must be less than or equal to the value of the form field ending "max". */
if(objName.substring((objName.length-3),objName.length)=="min")
{
var objMaxName = objName.substring(0, (objName.length-3)) + "max";
if(document.getElementById(objMaxName) != undefined && document.getElementById(objMaxName) != "undefined" )
{
if(checkIntervalObjs(object, document.getElementById(objMaxName)) != true)
return false;
}
}
}
}
return true;
}
/* Check the correctness of all input items in the form, generally used for the onsubmit event of the form*/
function checkForm(myform)
{
var i;
for (i=0;i<myform.elements.length;i++)
{
/* Non-custom attributes are ignored*/
if (myform.ements[i].eos_displayname + "" == "undefined") continue;
/* Non-empty check*/
if (myform.elements[i].eos_isnull=="false" && isnull(myform.elements[i].value)){
f_alert(myform.elements[i],"cannot be empty");
return false;
}
/* Data type verification*/
if (checkInput(myform.elements[i])==false)
return false;
}
return true;
}
/**
* Check the size of the data in the two form fields, currently only dates and numbers are allowed.
* @param obj1 small value form field
* @param obj2 Large value form field
*/
function checkIntervalObjs(obj1, obj2)
{
var caption1 = obj1.getAttribute("eos_displayname");
var caption2 = obj2.getAttribute("eos_displayname");
var val1 = parseFloat(obj1.value);
var val2 = parseFloat(obj2.value);
// Non-custom attributes are ignored
if (obj1.eos_displayname + "" == "undefined" || obj2.eos_displayname + "" == "undefined") {
return false;
}
// Comparison of date types
if(f_check_date(obj1) == true && f_check_date(obj2) == true){
var dtype = obj1.eos_datatype;
var format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //Date format
val1 = getDateByFormat(obj1.value, format);
dtype = obj2.eos_datatype;
format = dtype.substring(dtype.indexOf("(")+1,dtype.indexOf(")")); //Date format
val2 = getDateByFormat(obj2.value, format);
if(val1 > val2){
obj2.select();
if(isVisible(obj) && checkPrVis(obj))
obj2.focus();
alert(caption1 + "The start date cannot be greater than its end date!");
return false;
}
}
// Comparison of numeric types
if((isNaN(val1) && !isnull(val1)) || (isNaN(val2) && !isnull(val2))){
alert(caption1 + "If the values of not all numbers are numbers, they cannot be compared!");
return false;
}
if(val1 > val2){
obj2.select();
if(isVisible(obj) && checkPrVis(obj))
obj2.focus();
alert(caption1 + "The starting value of cannot be greater than its end value!");
return false;
}
return true;
}
/* Convert string to Date object according to date format.
Format: yyyy-year, MM-month, dd-day, HH-hour, mm-minute, ss-second.
(The format must be written in full, for example: yy-Md, which is not allowed, otherwise null will be returned; the format does not match the actual data and will also return null.)
Default format: yyyy-MM-dd HH:mm:ss,yyyy-MM-dd. */
function getDateByFormat(str){
var dateReg,format;
var y,M,d,H,m,s,yi,Mi,di,Hi,mi,si;
if((arguments[1] + "") == "undefined") format = "yyyy-MM-dd HH:mm:ss";
else format = arguments[1];
yi = format.indexOf("yyyy");
Mi = format.indexOf("MM");
di = format.indexOf("dd");
Hi = format.indexOf("HH");
mi = format.indexOf("mm");
si = format.indexOf("ss");
if(yi == -1 || Mi == -1 || di == -1) return null;
else{
y = parseInt(str.substring(yi, yi+4));
M = parseInt(str.substring(Mi, Mi+2));
d = parseInt(str.substring(di, di+2));
}
if(isNaN(y) || isNaN(M) || isNaN(d)) return null;
if(Hi == -1 || mi == -1 || si == -1) return new Date(y, M-1, d);
else{
H = str.substring(Hi, Hi+4);
m = str.substring(mi, mi+2);
s = str.substring(si, si+2);
}
if(isNaN(parseInt(y)) || isNaN(parseInt(M)) || isNaN(parseInt(d))) return new Date(y, M-1, d);
else return new Date(y, M-1, d,H, m, s);
}
/*LTrim(string): Remove the space on the left*/
function LTrim(str){
var whitespace = new String(" /t/n/r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1){
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
j++;
}
s = s.substring(j, i);
}
return s;
}
/*RTrim(string): Remove the space on the right*/
function RTrim(str){
var whitespace = new String(" /t/n/r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
var i = s.length - 1;
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
i--;
}
s = s.substring(0, i+1);
}
return s;
}
/*Trim(string): Remove spaces on both sides of the string*/
function Trim(str){
return RTrim(LTrim(str));
}