Common JS Summary 2 prototype

Source: Internet
Author: User
/*** Zip code ** STR: the string to be checked */string. Prototype. ispost = function () {If (! This. match (/^ \ W + (-\ W +) | (\. \ W +) * \ @ [A-Za-z0-9] + ((\. |-) [A-Za-z0-9] + )*\. [A-Za-z0-9] + $/) {return false;} return true;}/*** remove space * @ memberof {typename} * @ return {typename} */string. prototype. trim = function () {var M = This. match (/^ \ s * (\ s +) *) \ s * $/); Return (M = NULL )? "": M [1];}/*** is the mobile phone number * STR: the string to be checked */string. prototype. ismobile = function () {return (/^ (?: 13 \ d | 15 [89] | 18 \ d | 14 \ D )-? \ D {5} (\ D {3} | \ * {3}) $ /. test (this. trim ();}/*** whether it is a phone number * STR: the string to be checked * the phone number must have a zone number, which can contain a Location Number */string. prototype. istel = function () {return (/^ ([0 \ +] \ D {2, 3 }-)? (0 \ D {2, 3})-) (\ D {6, 8}) (-(\ D {3 ,}))? $ /. Test (this. trim ();}/*** only Chinese characters can be entered * @ memberof {typename} * @ return {typename} */string. prototype. ischinese = function () {var Re = new Regexp ("^ [\ u4e00-\ u9fa5] + $", ""); Return re. test (this. trim ();}/*** check whether it is a number. It can be a decimal number * @ return {typename} */string. prototype. isnumber = function () {If (! This) return false; var STRP =/^ \ D + (.)? (\ D + )? $/; Return STRP. test (this);}/*** is a valid QQ number * STR: the string to be checked */string. prototype. isqq = function () {If (/^ \ D {5, 9} $ /. test (this) {return true;} return false;}/*** is a valid IP * STR: the string to be checked */string. prototype. isip = function () {var Reg =/^ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0 )\. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [0-9]) $/; If (Reg. test (this) {return true;} return false;}/*** is a valid date * STR: the string to be checked */string. prototype. isdate = function () {var Reg =/^ (1 [6-9] | [2-9] \ D) \ D {2})-(0? [1, 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-) $/; If (Reg. Test (STR) {return true;} return false ;}

Call:

var str = ' qq ';var reslut = str.Trim();alert(reslut);//qq

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.