一般我在写Javascript文件时把一些最基本的函数写在一个文件里,供其它js文件调用,并命名为base.js
//Wipe off the blank
function trim(str){
return str.replace(/(^/s*)|(/s*$)/g, "");
}
//Check the string ,it should compose with the english , number, "_" or "-"
function isCharacter(str) {
var strRequest = /^([a-zA-Z0-9._-])+/;
if(strRequest.test(str)) {
return true;
}
return false;
}
//Check the email format, it should give the value just like abc_efg@163.com ,the symbol "@" and "." must be contained.
function isEmail(email) {
var emailRequest = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(/.[a-zA-Z0-9_-])+/;
if(emailRequest.test(email)) {
return true;
}
return false;
}
//Check the value ,if it empty ,return false
function isEmpty(str) {
str = trim(str);
if(str === null || str === "") {
return true;
}
return false;
}
//The string's length can't larger than the maxLength
function overMaxLeng(str, maxLength) {
var strLeng = str.leng;
if(strLeng > maxLength) {
return true;
}
return false;
}
//The string's length can't less than the minLength
function lessMinLeng(str, minLength) {
var strLeng = str.leng;
if(strLeng < minLength) {
return true;
}
return false;
}
//Wipe off the blank
function trim(str){
return str.replace(/(^/s*)|(/s*$)/g, "");
}
//Check the string ,it should compose with the english , number, "_" or "-"
function isCharacter(str) {
var strRequest = /^([a-zA-Z0-9._-])+/;
if(strRequest.test(str)) {
return true;
}
return false;
}
//Check the email format, it should give the value just like abc_efg@163.com ,the symbol "@" and "." must be contained.
function isEmail(email) {
var emailRequest = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(/.[a-zA-Z0-9_-])+/;
if(emailRequest.test(email)) {
return true;
}
return false;
}
//Check the value ,if it empty ,return false
function isEmpty(str) {
str = trim(str);
if(str === null || str === "") {
return true;
}
return false;
}
//The string's length can't larger than the maxLength
function overMaxLeng(str, maxLength) {
var strLeng = str.leng;
if(strLeng > maxLength) {
return true;
}
return false;
}
//The string's length can't less than the minLength
function lessMinLeng(str, minLength) {
var strLeng = str.leng;
if(strLeng < minLength) {
return true;
}
return false;
}