`
freeman983
  • 浏览: 231922 次
社区版块
存档分类
最新评论

5173的common.js

阅读更多
写道
function include(path,type,title){
var s,i,t;
if(arguments.length < 1){
return ;
}
if(arguments.length == 1){
type = "js";
}
switch(type.toLowerCase()){
case "css":
t = document.getElementsByTagName("link");
for(i=0;i<t.length;i++){
if(t[i].href && t[i].href.indexOf(path)!=-1){
return;
}
}
s=document.createElement("link");
s.rel="alternate stylesheet";
s.type="text/css";
s.href=path;
s.title=title;
s.disabled=false;
break;
case "js":
case "javascript":
default:
t = document.getElementsByTagName("script");
for(i=0;i<t.length;i++){
if(t[i].src && t[i].src.indexOf(path)!=-1){
return;
}
}
s=document.createElement("script");
s.type="text/javascript";
s.src=path;
break;
}
var h=document.getElementsByTagName("head")[0];
h.appendChild(s);
}

function trim(s){
return rtrim(ltrim(s));
}

function ltrim(s){
return s.replace( /^\s*/, "");
}

function rtrim(s){
return s.replace( /\s*$/, "");
}

function isEmpty(s){
s = trim(s);
return s.length == 0;
}

function isEmail(s){
s = trim(s);
var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i;
return p.test(s);
}

function isNumber(s){
return !isNaN(s);
}

function isColor(s){
s = trim(s);
if (s.length !=7) return false;
return s.search(/\#[a-fA-F0-9]{6}/) != -1;
}

function isMobile(s){
s = trim(s);
var p = /13\d{9}/;
return p.test(s);
}

function isCard(s){
s = trim(s);
var p = /^\d{15}(\d{2}[xX0-9])?$/;
return p.test(s);
}

function isURL(s){
s = trim(s).toLowerCase();
var p = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
return p.test(s);
}

function isPhone(s){
s = trim(s);
var p = /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/;
return p.test(s);
}

function isZip(s){
s = trim(s);
var p = /^[1-9]\d{5}$/;
return p.test(s);
}

function isDouble(s){
s = trim(s);
var p = /^[-\+]?\d+(\.\d+)?$/;
return p.test(s);
}

function isInteger(s){
s = trim(s);
var p = /^[-\+]?\d+$/;
return p.test(s);
}

function isEnglish(s){
s = trim(s);
var p = /^[A-Za-z]+$/;
return p.test(s);
}

function isChinese(s){
s = trim(s);
var p = /^[\u0391-\uFFE5]+$/;
return p.test(s);
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics