One.js verification function Verify mobile phone mailbox/email zip code ID card Chinese ip
http://blog.sina.com.cn/s/blog_4481a3460100jkyk.html
Email verification: function jsmail (mail) {return (newRegExp (/ ^ \ w + ((- \ w +) | (\. \ w +)) * \ @ [A-Za-z0-9] + ((\. | -) [A -Za-z0-9] +) * \. [A-Za-z0-9] + $ /). Test (mail));} Mobile number verification: function isMobel(value) { if(/^13\d{9}$/g.test(value)||(/^15[0-35-9]\d{8}$/g.test(value))|| (/^18[05-9]\d{8}$/g.test(value))){ returntrue; }else{ returnfalse; } } // remove left space function LTrim(str) { return str.replace(/^\s*/g,""); } // remove right space function RTrim(str) { return str.replace(/\s*$/g,""); } //remove spaces from both ends of the string function trim(str) { return str.replace(/(^\s*)|(\s*$)/g,""); } //remove spaces in the string function CTim(str) { return str.replace(/\s/g,''); } //Is it a string of numbers function is_digitals(str) { var reg=/^[0-9]*$/;//match integer returnreg.test(str); } //Verify whether it is an integer, including positive and negative numbers; function Is_Int(str) { var reg = / ^ (- | \ +)? d + $ /; return reg.test(str); } // is an integer greater than 0 function Is_positive_num(str) { var reg = / ^ \ d + $ /; return reg.test(str); } // check for negative integers function Is_minus(str) { var reg = / ^ - \ d + $ /; return reg.test(str); } // Verify if it is a floating point number (positive number) function IsPositiveFloat(str) { var check_float =newRegExp("^[1-9][0-9]*\.[0-9]+$");//Match floating point numbers return check_float.exec(str); } //Whether it is a landline phone, the area code is 3 to 4 digits, the number is 7 to 8 digits, the area code and number are separated by "-", and the transfer number is 1 to 6 digits, enclosed in parentheses and followed by the number function IsTelphone(str) { varreg = / ^ [0-9] {3,4} \ - \ d {7,8} (\ (\ d {1,6} \))? $ /; if(reg.test(str)) return true; else return false; } //Taiwan mobile phone number format var tel = / ^ (09) d {8} $ /; if(phone.value=="" || (!tel.test(phone.value))) { alert('Please fill in the correct (mobile phone format 09xxxxxxxx )!'); phone.focus(); return false; } //Mobile phone number verification, verify 13 series and 158, 159 numbers, length 11 digits function IsMobel(str) { var reg0 = / ^ 13 \ d {9} $ /; var reg1 = / ^ 158 \ d {8} $ /; var reg2 =/^159\d{8}$/; return(reg0.test(str)||reg1.test(str)||reg2.test(str)) } // Verify if it is Chinese function IsChinese(str) { var reg = / ^ [\ u0391- \ uFFE5] + $ /; return reg.test(str); } //Verify whether it is a QQ number, the length is 5-10 digits function IsQq(str) { var reg = / ^ [1-9] \ d {4.9} $ /; return reg.test(str); } // verify zip code function IsPostId(str) { var reg = / ^ \ d {6} $ /; return reg.test(str); } //Verify if not emailed function IsEmail(str) { varreg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; or var myreg = / ^ [-_ A-Za-z0-9 \.] + @ ([_ A-Za-z0-9] + \.) + [A-Za-z0-9] {2,3} $ / ; return reg.test(str); } // Verify IP address function IsIp (str) { var check=function(v) { try { return(v<=255 &&v>=0) }catch(x){ return false; } } var re=str.split(".") return (re.length==4)?(check(re[0])&& check(re[1])&& check(re[2])&& check(re[3])):false } // ID verification function IsIdnum(str) { varCity={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: "***", 71: "Taiwan", 81: "Hong Kong", 82: "Macau", 91:"Foreign"} var iSum = 0 var info="" if(!/^\d{17}(\d|x)$/i.test(str)) return false; str=str.replace(/x$/i,"a"); if(City[parseInt(str.substr(0,2))]==null) { alert( "Error: illegal region"); return false; } sBirthday=str.substr(6,4)+"-"+Number(str.substr(10,2))+"-"+Number(str.substr(12,2)); var d=newDate(sBirthday.replace(/-/g,"/")) if(sBirthday!=(d.getFullYear()+"-"+(d.getMonth()+1) + "-" + d.getDate())) { alert("Error: illegal birthday"); return false; } for(var i = 17;i>=0;i--) iSum += (Math.pow(2,i) % 11) * parseInt(str.charAt(17 - i),11) if(iSum%11!=1) { alert("Error: illegal license number"); return false; } returnCity[parseInt(str.substr(0,2))]+","+sBirthday+","+(str.substr(16,1)%2?"男":"女") } //Determine whether it is a short time, like (13:04:06) function IsTime(str) { var a =str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/); if (a == null) { alert('The input parameter is not in time format'); return false; } if (a[1]>24 ||a[3]>60 || a[4]>60) { alert("Time format is incorrect"); return false } return true; } //Short date, like (2003-12-05) function IsDate(str) { var r = str.match (/ ^ (\ d {1,4}) (- | \ /) (\ d {1,2}) \ 2 (\ d {1,2}) $ /); if(r==null) return false; var d= new Date(r[1], r[3]-1,r[4]); return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]); } // long time, like (2003-12-05 13:04:06) function IsDateTime(str) { var reg =/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})(\d{1,2}):(\d{1,2}):(\d{1,2})$/; var r = str.match (reg); if(r==null) return false; var d= new Date(r[1],r[3]-1,r[4],r[5],r[6],r[7]); return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]); } // Judging that the characters are all composed of aZ or AZ letters function Is_Letters(str) { var reg = / [^ a-zA-Z] / g; return reg.test(str); } // Judging characters are composed of letters and numbers. function Is_letter_num(str) { var reg = / [^ 0-9a-zA-Z] / g; return reg.test(str); } //The judgment character consists of letters and numbers, underscores, and dots. And the beginning can only be underscores and letters function IsUserName(str) { var reg = / ^ ([a-zA-z _] {1}) ([\ w] *) $ / g; return reg.test(str); } // Determine the type of browser function GetBrowseType() { alert(window.navigator.appName); } / / Determine the version of ie function Get_Eidition() { alert(window.navigator.appVersion); } / / Determine the resolution of the client function GetResolution() { alert(window.screen.height); alert(window.screen.width); } // Determine whether the user name is a number and letter swipe function notchinese(str) { var reg = / [^ A-Za-z0-9 _] / g if(reg.test(str)) { return (false); } else { return(true); } } // verify url function IsUrl(str) { varreg = / ^ (http \: \ / \ /)? ([a-z0-9] [a-z0-9 \ -] + \.)? [a-z0-9] [a-z0-9 \ -] + [a-z0-9] (\. [az] {2,4}) + (\ / [a-z0-9 \. \, \ - \ _ \% \? \ = \ &]? )? $ / i; return reg.test(str); } // Determine whether it contains Chinese characters function ContentWord(str) { if (escape(str).indexOf("%u")!=-1) return true; else return false; } // carriage return to the focus of the next control in the page function Enter2Tab(e) { try { var ōb = IsFireFox ? e.target : event.srcElement; if(ob.tagName == "INPUT" &&(ob.type== "text" ||ob.type == "password" ||ob.type == "checkbox" ||ob.type == "radio") ||ob.tagName == "SELECT") { var key = IsFireFox ? e.which : event.keyCode; if (key == 13) { if (IsFireFox) { event.which = 9; } else { event.keyCode = 9; } } } } catch(E){} } function InitAjax() { var ajax = false; try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajax =new ActiveXObject("Microsoft.XMLHTTP"); } catch(E) { ajax = false; } } if (!ajax&& typeofXMLHttpRequest!='undefined') { ajax = new XMLHttpRequest(); } return ajax; } function callback(ajax) { //If the execution is in normal state, then assign the returned content to the layer specified above if (ajax.readyState == 4&& ajax.status == 200) { show.innerHTML =ajax.responseText; } else { alert("there was a problem retrieving the xmldata:"+ajax.statusText); } } function getNews(newsID) { //If the parameter newsID is not passed in if (typeof(newsID) == 'undefined') { return false; } //The URL address that needs to be used for Ajax var url = "show.php?id="+ newsID; //Get the position of the news display layer var show =document.getElementByIdx("show_news"); //Instantiate the Ajax object var ajax = InitAjax(); //Use the Get method to request ajax.open("GET",url,true); //get execution status ajax.onreadystatechange=function() { if (ajax.readyState == 4&& ajax.status == 200) { show.innerHTML =ajax.responseText; } } // send empty ajax.send(null); } //_______Select all__________ function SelectAll() { varempty; var f =document.forms[0]; for (var i =0; i < f.length; i++) { empty = f[i]; if (empty.type == "checkbox" &&empty.disabled == false) empty.checked = true; } } //__________Return to select __________ function SelectReverse() { varempty; var f =document.forms[0]; for (var i =0; i < f.length; i++) { empty = f[i]; if (empty.type == "checkbox" &&empty.disabled == false) if(empty.checked == true) { empty.checked = false; } else { empty.checked = true; } } }
2. JS has 3 ways to get elements
Source: http://www.popo4j.com/tag/DOM.html
There are 3 ways to get elements in native JS:
- getElementById('id')
- getElementsByName('name')
- getElementsByTagName('tag')
getElementById is the fastest way to get elements, but we can't give each HTML element an ID, so we need a very convenient way to get elements by classname:
function getElementsByClassName(className,tagName){ var ele=[],all=document.getElementsByTagName(tagName||"*"); for(var i=0;i<all.length;i++){ if(all[i].className==className){ he[ele.length]=all[i]; } } return it; } console.log(getElementsByClassName("entry")); console.log(getElementsByClassName("entry","div"));
- Please indicate: js verification function to verify mobile phone mailbox/email zip code ID card Chinese ip and S There are 3 ways to get elements |
http://www.xuebuyuan.com/2108060.html