Some functions commonly used in Javascript are collected and shared. The specific functions are as follows: functions that return the id attribute value node from the original ecology, remove spaces on the left of the string, remove spaces on the right of the string, and remove spaces on the string twice, verify email address, verify the number range of strings, verify the date format, verify whether a positive integer, and so on.
// ****************** Return the node value of the id attribute *************** * ********** function $ (id) {return document. getElementById (id );} // ****************** remove the left space ***************** * ******* function ltrim (s) {return s. replace (/^ \ s */,"");} // ****************** remove the right space ***************** * ******* function rtrim (s) {return s. replace (/\ s * $ /,"");} // ******************* remove left and right spaces ***************** * ******* function trim (s) {return ltrim (rtrim (s ));}// ***************** * ******* Function checkcharnum_range (str, lt, gt) {if (trim ($ (str ). value ). length <lt) {return false;} if (trim ($ (str ). value ). length> gt) {return false ;}} ****************** * ****** function isEmail (str) {var reg =/^ ([a-zA-Z0-9 _-]) + @ ([a-zA-Z0-9 _-]) + ((\. [a-zA-Z0-9 _-] {2, 3}) {1, 2}) $/; return reg. test (str );} // ****************** verify the integer ************** * *********** Function isInteger (str) {var regu =/^ [-] {0, 1} [0-9] {1 ,} $/; return regu. test (str );} ****************** * ****** function isDate (str) {if (trim (str) = "") return false; var r = str. match (/^ (\ d {}) (-| \/) (\ d {}) \ 2 (\ d {}) $ /); // year, month, and day Regular Expression if (r = null) {alert ("enter the correct date \ n \ r date format: yyyy-mm-dd \ n \ r example: 2008-08-08 \ n \ r "); return false;} var d = new Date (r [1], r [3]-1, r [4]); var num = (d. ge TFullYear () = r [1] & (d. getMonth () + 1) = r [3] & d. getDate () = r [4]); if (num = 0) {alert ("enter the correct date \ n \ r date format: yyyy-mm-dd \ n \ r example: 2008-08-08 \ n \ r ");} return (num! = 0 );} // ***************** verify the positive integer ****************** * ****** function isNum (str) {var reg =/^ [1-9] \ d * $/; return reg. test (str );}
Articles you may be interested in
- Collect common php functions with explanations
- Php uses the filter function to verify the mailbox, url, and IP address
- PHP compresses html webpage code to reduce the amount of network data transmitted, clear spaces, tabs, and comment mark
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- How does php clear html format, remove spaces in text, and intercept text?
- Php uses array_flip to implement array key-value exchange to remove array duplicate values
- Php uses the ZipArchive function to compress and decompress files.
- Php extracts the birthday date from the ID card number and verifies whether it is a minor.