Some JavaScript detection functions that are often used

zhaozj2021-02-16  67

// Function Name: Trim

// Function Description: The first end of the string

// Creation Date: 2004-7-13 15:30

// last modify by: N / A

// last modify date: n / a

String.prototype.trim = function () {

Return this.Replace (/ (^ / s *) | (/ s * $) / g, "");

}

// Function Name: LTRIM

// Function Description: Space for removing the left side of the string

// Creation Date: 2004-7-13 9:58

// last modify by: N / A

// last modify date: n / a

String.Prototype.ltrim = function ()

{

Return this.Replace (/ (^ / s *) / g, "");

}

// Function Name: RTRIM

// Function Description: Removes the space of the right side of the string

// Creation Date: 2004-7-13 15:31

// last modify by: N / A

// last modify date: n / a

String.prototype.rtrim = function ()

{

Return this.Replace (/ S * $) / g, "");

}

// function name: LEN

// Function Description: Returns the actual length of the string, one Chinese word counts 2 lengths

// Creation Date: 2004-7-13 9:58

// last modify by: N / A

// last modify date: n / a

String.Prototype.len = function ()

{

Var str = this;

Return str.replace (/ [^ / x00- / xff] / g, "**"). Length

}

// function name: isvaliddate

// Function Description: Judging whether the input is a valid short date format - "YYYY-MM-DD"

// Creation Date: 2004-7-13 9:58

// last modify by: N / A

// last modify date: n / a

String.prototype.issaliddDate = function ()

{

Var Result = this.match (/ ^ (/ D {1, 4}) (- | //) (/ D {1, 2}) / 2 (/ D {1, 2}) $ /);

IF (result == null) Return False;

VAR D = New Date (Result [1], Result [3] -1, Result [4]);

Return (D.Getfullyear () == Result [1] && D.getMonth () 1 == Result [3] && d.getdate () == Result [4]);

}

// Function name: isvalidtime

// Function Description: Determine if the input is a valid time format - "hh: mm: ss"

// Creation Date: 2004-7-13 9:58

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidtime = function () {

Var resule = this.match (/ ^ (/ d {1, 2}) (:)? (/ d {1, 2}) / 2 (/ d {1, 2}) $ /);

IF (result == null) Return False;

IF (Result [1]> 24 || Result [3]> 60 || Result [4]> 60) RETURN FALSE

Return True;

}

// Function name: isvalidemail

// Function Description: Judging whether the input is an effective email

// creation date: 2004-7-13 9:59

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidemail = function ()

{

Var Result = this.match (/ ^ / w ) | (/ w )) * / @ [A-ZA-Z0-9] (/. | -) [A-ZA- Z0-9] ) * /. [A-ZA-Z0-9] $ /);

IF (result == null) Return False;

Return True;

}

// function name: isvaliddatetime

// Function Description: Judging whether the input is a valid long-term format - "YYYY-MM-DD HH: MM: SS"

// creation date: 2004-7-13 9:59

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAliddateTime = function ()

{

Var Result = this.match (/ ^ (/ d {1, 4}) (- | //) (/ D {1, 2}) / 2 (/ d {1, 2}) (/ D {1, 2}): (/ D {1, 2}): (/ d {1, 2}) $ /);

IF (result == null) Return False;

VAR D = New Date (Result [1], Result [3] -1, Result [4], Result [5], Result [6], Result [7]);

Return (D.Getfullyear () == Result [1] && (d.getMonth () 1) == Result [3] && d.getdate () == Result [4] && d.Gethours () == Result [5 ] && d.getminutes () == Result [6] && D.getSeconds () == Result [7]);

}

// Function name: isvalidinteger

// Function Description: Judging whether the input is an integer

// Creation Date: 2004-7-13 10:01

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidinteger = function ()

{

Var Result = this.match (/ ^ (- | / )? / d $ /);

IF (result == null) Return False;

Return True;

}

// function name: isvalidpositiveinteger // function description: Judging whether the input is a positive integer

// Creation Date: 2004-7-13 10:01

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidPositiveInteger = function ()

{

Var Result = this.match (/ ^ / d $ /);

IF (result == null) Return False;

IF (Parseint (this)> 0) Return True;

Return False;

}

// Function name: isvalidnegativeinteger

// Function Description: Determine if the input is a negative integer

// Creation Date: 2004-7-13 10:28

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidnegativeinteger = function ()

{

Var result = this.match (/ ^ - / d $ /);

IF (result == null) Return False;

Return True;

}

// Function name: isvalidNumber

// Function Description: Judging whether the input is a number

// Creation Date: 2004-7-13 10:01

// last modify by: N / A

// last modify date: n / a

String.Prototype.issalidNumber = function ()

{

Return! isnan (this);

}

// Function name: isvalidletters

// Function Description: Judging whether the input is a string consisting of A-Z / A-Z

// Creation Date: 2004-7-13 10:10

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidletters = function ()

{

Var Result = this.match (/ ^ [a-za-z] $ /);

IF (result == null) Return False;

Return True;

}

// function name: isvaliddigits

// Function Description: Judging whether the input is a number composed of 0-9

// Creation Date: 2004-7-13 10:10

// last modify by: N / A

// last modify date: n / a

String.prototype.issAliddigits = function ()

{

Var Result = this.match (/ ^ [1-9] [0-9] $ /);

IF (result == null) Return False;

Return True;

}

// function name: isvalidalphanumeric

// Function Description: Judging whether the input is a string consisting of 0-9 / A-Z / A-Z

// Creation Date: 2004-7-13 10:14

// last modify by: n / a // last modify date: n / a

String.Prototype.issalidalPhanumeric = function ()

{

Var Result = this.match (/ ^ [A-ZA-ZA-Z0-9] $ /);

IF (result == null) Return False;

Return True;

}

// function name: isvalidstring

// Function Description: Determined whether the input is a string consisting of 0-9 / a-z / a-z /. / _

// Creation Date: 2004-7-13 10:20

// last modify by: N / A

// last modify date: n / a

String.prototype.issalidstring = function ()

{

Var Result = this.match (/ ^ [A-ZA-ZA-Z0-9 / s ./-_] or all);

IF (result == null) Return False;

Return True;

}

// function name: isvalidPostalcode

// Function Description: Judging whether the input is a valid zip code

// Creation Date: 2004-7-13 10:22

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidPostalcode = function ()

{

Var Result = this.match (/ (^ [0-9] {6} $) /);

IF (result == null) Return False;

Return True;

}

// function name: isvalidphoneno

// Function Description: Judgment is a valid phone number

// Creation Date: 2004-7-13 10:22

// last modify by: N / A

// last modify date: n / a

String.Prototype.issAlidPhoneno = function ()

{

Var result = this.match (/ (^ [0-9] {3, 4} / - [0-9] {3,8} $) | (^ [0-9] {3,8} $) | (^ / ([0-9] {3, 4} /) [0-9] {3, 8} $) /);

IF (result == null) Return False;

Return True;

}

// function name: isvalidMobileno

// Function Description: Judging whether the input is a valid mobile number

// Creation Date: 2004-7-13 10:23

// last modify by: N / A

// last modify date: n / a

String.Prototype.issalidMobileno = function ()

{

Var result = this.match (/ (^ 0 {0, 1} 13 [0-9] {9} $) /);

IF (result == null) Return False;

Return True;

}

转载请注明原文地址:https://www.9cbs.com/read-15356.html

New Post(0)