-
<转>常用的js验证
- //添加时间侦听
- function addListener(e, eventType, listener)
- {
- Event.observe(e, eventType, listener);
- };
-
-
- function IsNone(s)
- {
- return s.toString().empty();
- }
-
-
- function IsEmpty(s)
- {
- return s.toString().blank();
- }
-
-
- function IsNumber(s)
- {
- s = s.toString();
- if (s.empty() || s.blank())
- return false;
- return !isNaN(s);
- }
-
-
- function IsInteger(s)
- {
- if (!IsNumber(s))
- return false;
- s = (s - 0).toString();
- return s.match(/^[-]?/d{1,15}$/gi) != null;
- }
-
-
- function IsDouble(s)
- {
- if (!IsNumber(s))
- return false;
- s = (s - 0).toString();
- if (s.match(/^[-]?(/d+)[.]?(/d+)$/gi) == null)
- return false;
- return RegExp.$1.length + RegExp.$2.length <= 17;
- }
-
- function IsDate(s)
- {
- var reg = /^((((1[6-9]|[2-9]/d)/d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]/d|3[01]))|(((1[6-9]|[2-9]/d)/d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]/d|30))|(((1[6-9]|[2-9]/d)/d{2})-0?2-(0?[1-9]|1/d|2[0-8]))|(((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/;
- return reg.test(s);
- }
-
- function IsTime(str)
- {
- var tmp = str.toString();
- return (tmp.match(/^([01]?[0-9]|2[0-3]):([012345]?[0-9]|5[1-9]):([012345]?[0-9]|5[1-9])$/g) != null)
- }
-
-
-
- function isEmail(str)
- {
- return str.toString().match(/^(?:[;]?[/w_-]+(?:[.][/w_-]+)*@[/w_-]+(?:[.][/w_-]+)+)+$/gi) != null;
- }
-
- function isQQ(str)
- {
- return str.toString().match(/^[1-9]/d{4,12}$/g) != null;
- }
-
-
- function isPhone(str)
- {
- return str.toString().match(/^((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?$/g) != null;
- }
-
-
- function isMobile(str)
- {
- return str.toString().match(/^((/(/d{2,3}/))|(/d{3}/-))?1/d{10}$/g) != null;
- }
-
-
-
- function isPhoneOrMobileList(str)
- {
- return str.toString().match(/^((((/(/d{2,3}/))|(/d{3}/-))?1/d{10})|(((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?))(,((((/(/d{2,3}/))|(/d{3}/-))?1/d{10})|(((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?)))*$/g) != null;
- }
-
-
- function isEmailList(emails)
- {
- return emails.all(function(email) { return isEmail(email.strip()); });
- }
-
-
- function isAscii(str)
- {
- return str.toString().match(/^[A-Za-z0-9,-]*$/gi) != null;
- }
-
-
- function isUrl(str)
- {
- return str.toString().match(/^(http|https):
- }
-
- function isFtp(str)
- {
- return str.toString().match(/^ftp:
- }
-
- function isPostCode(str)
- {
- return str.toString().match(/^[0-9]{6}$/g) != null;
- }
-
-
- function checkEmailsReteration(emails)
- {
- return emails.length > emails.map(function(email) { return email.strip().toLowerCase(); }).uniq().length;
- }
-
-
- function ResizeImage(handleObj,w,h)
- {
- var coll = handleObj.select("img");
- for(var i = 0; i < coll.length; i++)
- {
- var iWidth = coll[i].width;
- var iHeight = coll[i].height;
- if(coll[i].style.width != "")
- iWidth = parseInt(coll[i].style.width);
- if(coll[i].style.height != "")
- iHeight = parseInt(coll[i].style.height);
- if(iWidth >= iHeight)
- {
- if(iWidth> w)
- {
- if(coll[i].style.width != "")
- {
- coll[i].style.width = w;
- coll[i].style.height = (w * iHeight)/ iWidth;
- }
- else
- {
- coll[i].width = w;
- coll[i].height = (w * iHeight)/ iWidth;
- }
- }
- }
- else
- {
- if(iHeight > h)
- {
- if(coll[i].style.width != "")
- {
- coll[i].style.width = (h * iWidth)/ iHeight;
- coll[i].style.height = h;
- }
- else
- {
- coll[i].height = h;
- coll[i].width = (h * iWidth)/ iHeight;
- }
- }
- }
- }
- }
-
- function ResizeImageInWidth(handleObj,w,h)
- {
- var coll = handleObj.select("img");
- var newW = 0, newH = 0;
-
- for(var i = 0; i < coll.length; i++)
- {
- var iWidth = coll[i].width;
- var iHeight = coll[i].height;
- if(coll[i].style.width != "")
- iWidth = parseInt(coll[i].style.width);
- if(coll[i].style.height != "")
- iHeight = parseInt(coll[i].style.height);
- if(iWidth >= iHeight)
- {
- if(iWidth> w)
- {
- newW = w;
- newH = (w * iHeight)/ iWidth;
- }
- }
- else
- {
- if(iWidth> w)
- {
- newW = w;
- newH = (w * iHeight)/ iWidth;
- if(newH > (1.5*h))
- newH = 1.5*h;
- }
- else if(iHeight > (1.5*h))
- {
- newW = iWidth;
- newH = 1.5*h;
- }
- }
- if(newW > 0)
- {
- if(coll[i].style.width != "")
- {
- coll[i].style.width = newW;
- coll[i].style.height = newH;
- }
- else
- {
- coll[i].width = newW;
- coll[i].height = newH;
- }
- newW = 0;
- newH = 0;
- }
- }
- }
-
- function resizeImageByWidth(o, width)
- {
- var oldWidth = 0;
- var oldHeight = 0;
-
- if(o != null && width > 0)
- {
- oldWidth = parseInt(o.width);
- oldHeight = parseInt(o.height);
- if(oldWidth > 0 && oldHeight > 0)
- {
- var z = width / oldWidth;
- var height = parseInt(oldHeight * z);
- o.width = width;
- o.height = height;
- }
- }
- }
-
- function resizeImageByWidthEx(srcWidth, srcHeight, setWidth){
- return (srcWidth > 0 && srcHeight > 0 && srcWidth > setWidth) ? { setWidth, height: srcHeight * (setWidth / srcWidth)} : { srcWidth, height: srcHeight};
- }
-
- function SetSameHeight()
- {
- var divLeft = $("divDoorLeft");
- var divMiddle = $("divDoorMiddle");
- var divRight = $("divDoorRight");
- var divMain = $("divDoorMain");
- if(divLeft!=null)
- {
- var maxHeight = 0;
- if(divMain != null)
- {
- maxHeight = Math.max(divLeft.scrollHeight, divMain.scrollHeight);
- divLeft.style.height = maxHeight-25 + 'px';
- divMain.style.height = maxHeight + 'px';
- }
- else
- {
- maxHeight = Math.max(divLeft.scrollHeight,divMiddle.scrollHeight, divRight.scrollHeight);
- divLeft.style.height = maxHeight-25 + 'px';
- if(divMiddle.scrollHeight < maxHeight)
- divMiddle.style.height = maxHeight + 'px';
- divRight.style.height = maxHeight-25 + 'px';
- }
- }
- }
-
- function SetLate()
- {
- SetSameHeight.delay(1);
- }
-
- function MM_swapImgRestore()
- {
- var i,x,a=document.MM_sr;
- for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
- x.src=x.oSrc;
- }
-
- function MM_preloadImages() {
- var d=document;
- if(d.images)
- {
- if(!d.MM_p)
- d.MM_p = [];
- var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
- for(i=0; i<a.length; i++)
- if (a[i].indexOf("#")!=0)
- {
- d.MM_p[j]=new Image;
- d.MM_p[j++].src=a[i];
- }
- }
- }
-
- function MM_findObj(n, d)
- {
- var p,i,x;
- if(!d)
- d=document;
- if((p=n.indexOf("?"))>0&&parent.frames.length)
- {
- d=parent.frames[n.substring(p+1)].document;
- n=n.substring(0,p);
- }
- if(!(x=d[n])&&d.all)
- x=d.all[n];
- for (i=0;!x&&i<d.forms.length;i++)
- x=d.forms[i][n];
- for(i=0;!x&&d.layers&&i<d.layers.length;i++)
- x=MM_findObj(n,d.layers[i].document);
- if(!x)
- x = $(n);
- return x;
- }
-
- function MM_swapImage()
- {
- var i,j=0,x,a=MM_swapImage.arguments;
- document.MM_sr = [];
- for(i=0;i<(a.length-2);i+=3)
- if ((x=MM_findObj(a[i]))!=null)
- {
- document.MM_sr[j++]=x;
- if(!x.oSrc)
- x.oSrc=x.src;
- x.src=a[i+2];
- }
- }
-
-
- function gotoAnchorLocation(id)
- {
- var url = self.location.pathname;
- var search = self.location.search;
- self.location = url + search + "#cmt" + id;
- }
-
- function trim(str)
- {
-
- if (str.length == 0)
- return "";
- str = str.replace(/^/s/s*/, ''),
- ws =
- i = str.length;
- while (ws.test(str.charAt(--i))) ;
- return str.slice(0, i + 1);
- }
-
-
- function numberFormat (number, decimals, decPoint, thousandsSep) {
- var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 0 : decimals,
- d = decPoint === undefined ? "." : decPoint,
- t = thousandsSep === undefined ? "," : thousandsSep, s = n < 0 ? "-" : "",
- i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
- return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(/d{3})(?=/d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
- };
-
相关阅读:
Python单元测试之unittest基础
linux--硬链接和软链接
12-8 istio核心功能实战-----可观察性(程访问遥测插件)
12-7 istio核心功能实战-----可观察性(网络可视化)
12-6 istio核心功能实战-----可观察性(分布式追踪)
12-3 部署面向生产的istio-----核心组件
12 ServiceMesh代表作istio-----12-1 ServiceMes、Istio架构原理
11-7 Grafana看板和邮件报警
11-6 监控落地
11-4 部署前奏-Helm&Operator
-
原文地址:https://www.cnblogs.com/xiaohong/p/3169417.html
Copyright © 2020-2023
润新知