首页 js函数总结(Js function summary)

js函数总结(Js function summary)

举报
开通vip

js函数总结(Js function summary)js函数总结(Js function summary) js函数总结(Js function summary) Commonly used Javascript validation function summary published time: 2010-07-16 content sources: webmaster information collected as the number of project to do more and more, which use js place a lot of...

js函数总结(Js function summary)
js函数 总结 初级经济法重点总结下载党员个人总结TXt高中句型全总结.doc高中句型全总结.doc理论力学知识点总结pdf (Js function summary) js函数总结(Js function summary) Commonly used Javascript validation function summary published time: 2010-07-16 content sources: webmaster information collected as the number of project to do more and more, which use js place a lot of the same, this in their finishing some of the commonly used form validation js method, although there are some difference between and other js validation framework, but after all is a summary of something by yourself, in this record and share. JS validation / * * * 2010-7-13 * royal princes * love edge * js various forms data validation * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * digital inspection certificate * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * check whether a string of characters entered is all Numbers * input: STR string * return: true or flase; True means number * / The function checkNum (STR) { Return the STR. Match (\ D /) = = null; } / * * * check whether a string of characters entered is a decimal * input: STR string * return: true or flase; True means a decimal * / The function checkDecimal (STR) { If (STR) match (/ ^ -? \ d + (. \ \ d +)? $/ g) = = null) { Return false; } The else { Return true; } } / * * * check whether a string of characters entered is the integer data * input: STR string * return: true or flase; True is a decimal * / The function checkInteger (STR) { If (STR. Match (/ ^ + [-]? \ d * $/) = = null) { Return false; } The else { Return true; } } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * character test certificate * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * check whether a string of characters entered is a character * input: STR string * return: true or flase; True means that all characters do not contain Chinese characters * / The function checkStr (STR) { If (/ [^ \ x00 - \ XFF] / g.t est (STR)) { Return false; } The else { Return true; } } / * * * check whether a string of characters entered contains Chinese characters * input: STR string * return: true or flase; True means including Chinese characters * / The function checkChinese (STR) { If (STR).indexof (" % u ")! = -1) Return true; } The else { Return false; } } / * * * check whether the mailbox format entered is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkEmail (STR) { If (STR) match (/ [A Za - z0 - _ - 9] + [@] (\ S *) (net | com | | cn org | cc | | TV [0-9] {1, 3}) (\ S *)/g) = = null) { Return false; } The else { Return true; } } / * * * check the correct format of the phone number entered * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkMobilePhone (STR) { If (STR) match (/ ^ (? : 13 \ | d 15 [89]) -? \ d {5} (\ d {3} | \ * {3}) $/) = = null) { Return false; } The else { Return true; } } / * * * check that the fixed number of the input is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkTelephone (STR) { If (STR) match (/ ^ ((+] [0 \ \ d {2, 3} -)? (0 \ d {2, 3}) -) (\ d {7, 8}) (- (\ d {3}))? $/) = = null) { Return false; } The else { Return true; } } / * * * check whether the format of QQ is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkQQ (STR) { If (STR) match (/ ^ \ d {5, 10} $/) = = null) { Return false; } The else { Return true; } } / * * * check whether the id number of the input is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkCard (STR) { / / a 15-digit id card regex Var arg1 = / ^ 1-9] [\ d {7} ((0 \ d) | (1) [0-2]) ((\ d) [0 | 1 | 2] | 3 [0, 1]) \ d {3} $/; / / 18-digit id card regex Var arg2 = / ^ 1-9] [\ d {5} [1-9] \ d {3} ((0 \ d) | (1) [0-2]) ((\ d) [0 | 1 | 2] | 3 [0, 1]) ((\ d {4}) | \ d {3} [a-z]) $/; If (STR. Match (arg1) = = null & & STR. Match (arg2) = = null) { Return false; } The else { Return true; } } / * * * check that the IP address entered is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkIP (STR) { Var args = / ^ (\ d {1, 2} \ d \ d | 2 | 1 \ | d 25 [0-4] [0-5]) \. (\ d {1, 2} \ d \ d | 2 | 1 \ | d 25 [0-4] [0-5]) \. (\ d {1, 2} \ d \ d | 2 | 1 [0-4] \ | d 25 [0-5]) \. (\ d {1, 2} \ d \ d | 2 | 1 [0 to 4] \ | d 25 [0-5]) $/; If (STR. Match (arg) = = null) { Return false; } The else { Return true; } } / * * * check that the URL for the input is correct * input: STR string * return: true or flase; True indicates that the format is correct * / The function checkURL (STR) { If (STR) match (/ (HTTP [s]? | FTP) : \ / \ [^ \ / \] +? \.. + \ w $/ I) = = null) { Return false } The else { Return true; } } / * * * check if the entered character has a special character * input: STR string * return: true or flase; True represents a special character * it is mainly used to verify the registration information * / The function checkQuote (STR) { Var items = new Array (" - ", "`", "! ", "@", "#", "$"," % ", "^", "&", "*", "{","} ", ""," ", "(",") "); The items. Push (" : ", "; ", "'", "|", "\ \", "<", ">", "? ", "/", "< <", "> >", "| |", "/ /"); Push (" admin ", "administrators", "administrator", "administrator"); Items. Push (" select ", "delete", "update", "insert", "create", "drop", "alter", "trancate"); STR = STR. ToLowerCase (); For (var I = 0; I < item.length; I + +) { If (STR. IndexOf (items [I]) > = 0) { Return true; } } Return false; } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * the test of time card * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * check date format is correct * input: STR string * return: true or flase; True indicates that the format is correct * note: the Chinese date format cannot be verified here * short date (2007-06-05) * / The function checkDate (STR) { //var value=str.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/); Var value = STR. Match (/ ^ (\ d {1, 4}) (- | \ /) (\ d {1, 2}) \ 2 $/ (\ d {1, 2})); If (value = = null) { Return false; } The else { Var date = new date (value [1], value [3] -- 1, value [4]); Return (date. GetFullYear () = = value [1] & (date). GetMonth () + 1) = = value [3] && date. The getDate () = = value [4]); } } / * * * check whether the format is correct * input: STR string * return: true or flase; True indicates that the format is correct * verification time (10:57:10) * / The function checkTime (STR) { Var value = STR. Match (/ ^ (\ d {1, 2}) (?) (\ d {1, 2}) \ 2 $/ (\ d {1, 2})) If (value = = null) { Return false; } The else { If (value [1] >, >, | | value >, |, |, |, |, |, |, |, |, |, |, |, |, |, |, |, |, Return false } The else { Return true; } } } / * * * check whether the full date time format is correct * input: STR string * return: true or flase; True indicates that the format is correct * 10:57:10 (2007-06-05) * / The function checkFullTime (STR) { / / var value = STR. Match (/ ^ (\ d {1, 4}) (- | \ /) (\ d {1, 2}) \ 2 (\ d {1, 2}) (\ d {1, 2}) : (\ d {1, 2}) : (\ d {1, 2}) $/); Var value = STR. Match (/ ^ (20) : 19 | [0-9] [0-9] - (? : (? : 0 [1-9]) | (? : 1) [0-2]) - (? : (? : [2-0] [1-9]) | (? : [1-3] [0, 1])) ((? : [2-0] [0, 3]) | (? : [0-9] [0, 1])) : [0 to 5] [0-9] : [0 to 5] [0-9] $/); If (value = = null) { Return false; } The else { / / var date = new date (checkFullTime [1], checkFullTime [3] -- 1, checkFullTime [4], checkFullTime [5], checkFullTime [6], checkFullTime [7]); / / return (date. GetFullYear () = = value [3] & date.getdate () = = value [4] & date.gethours () = = value [5] & date. GetMinutes () = = value [5] & date. GetMinutes () = = value [6] & date. GetSeconds () = = value [7]); Return true; } } / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * id number validation of the * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * 15 bit coding rules for id card: DDDDDD yymmdd xx p * DDDDDD: region code * yymmdd: birth date * xx: sequential class encoding, cannot be determined * p: gender, odd number is male, even number is female * < / p > * body certificate 18 bit coding rules: DDDDDD yyyymmdd XXX y * DDDDDD: region code * yyyymmdd: birth date * XXX: sequential class coding, which cannot be determined, the odd number is male, even number is female * y: check code, which can be obtained from the first 17 digits * < / p > * 18 digit weighting factors (from right to left) Wi = 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1] * witness position Y = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2] * calibration position: Y_P = mod (Ai x Wi), 11) * the number of id card number from right to left. 18; Y_P is the location of the check code of the foot check code * * / Var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1); / / weighting factor Var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2]; / / the verification bit value of the id card. 10 represents X The function IdCardValidate (idCard) { IdCard = trim (idcard.replace (/ / g, "")); If (idcard.length = = 15) { Return isValidityBrithBy15IdCard (idCard); } The else If (idcar.length = = 18) { Var a_idCard = idCard. Split (" "); / / get an array of ids If (isValidityBrithBy18IdCard (idCard) && isTrueValidateCodeBy18IdCard (a_idCard)) { Return true; } The else { Return false; } } The else { Return false; } } / * * * determine if the last check digit is correct when the id number is 18 * @param a_idCard identification number array * @ return * / The function isTrueValidateCodeBy18IdCard (a_idCard) { Var sum = 0; / / declare a weighted sum variable If (a_idCard [17]. ToLowerCase () = = = 'x') { A_idCard [17] = 10; / / replace the last bit of the verification code of x with 10 convenient follow up operations } For (var I = 0; I < 17; I + +) { Sum + = Wi [I] * a_idCard [I]; / / weighted sum } ValCodePosition = sum % 11; / / get the verification code position If (a_idCard [17] = = = ValideCode [valcovariance]) { Return true; } The else { Return false; } } / * * * judging by id card is male or female * @param idCard 15/18 id number * @return 'female' - female, 'male' - male * / The function maleOrFemalByIdCard (idCard) { IdCard = trim (idcard.replace (/ / g, "")); / / handle the id card number. Including Spaces between characters. If (idcard.length = = 15) { If (idcard.substring (14, 15) % 2 = = 0) Return 'female'; } The else { Return the 'male'; } } The else If (idcar.length = = 18) { If (idcar.substring (14, 17) % 2 = = 0) { Return 'female'; } The else { Return the 'male'; } } The else { Return null; } } / * * * verify that the birthday in the 18-digit id number is a valid birthday * @param idCard 18 book id card string * @ return * / The function isValidityBrithBy18IdCard (idCard18) { Var year = idCard18. Substring (6, 10); Var month = idCard18. Substring (10, 12); Var day = idCard18. The substring (12, 14); Var temp_date = new Date (year, parseFloat (month) - 1, parseFloat (day)); / / get the year from getFullYear () to avoid the problem of y2k If (temp_date.getfullyear ()! = parseFloat (year), | | Temp_date. GetMonth ()! = parseFloat (month) - 1 | | Temp_date. GetDate ()! = parseFloat (day)) { Return false; } The else { Return true; } } / * * * verify that the birthday in the 15-digit id number is a valid birthday * @param idcard1515 book id string * @ return * / The function isValidityBrithBy15IdCard (idCard15) { Var year = idCard15. Substring (6, 8); Var month = idCard15. Substring (8, 10); Var day = idCard15. Substring (10, 12); Var temp_date = new Date (year, parseFloat (month) - 1, parseFloat (day)); / / for the age of your old id card you don't need to consider the millennium bug problem and use the getYear () method If (temp_date. GetYear ()! = parseFloat (year) Temp_date. GetMonth ()! = parseFloat (month) - 1 | | Temp_date. GetDate ()! = parseFloat (day)) { Return false; } The else { Return true; } } / / remove the headspace of the string The function trim (STR) { Return the STR. Replace (/ (^ \ s *) | (\ s * $)/g, ""); } Netizen review This article from the master of information network The original link:
本文档为【js函数总结(Js function summary)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_562397
暂无简介~
格式:doc
大小:51KB
软件:Word
页数:20
分类:
上传时间:2018-12-25
浏览量:21