Regular expression to do data verification judgment

xiaoxiao2021-03-05  19

First, verification class

1, digital verification

1.1 integer

/^ (-|/ )?/d //test(STR)

1.2 Entarity of greater than 0 (for verification of IDs)

/^ @Test (STR)

1.3 Verification of negative integers

/^-/d //.test(STR)

2, time class

2.1 short, shaped (13:04:06)

Function istime (STR)

{

VAR a = str.match (/ ^ (/ d {1, 2}) (:)? (/ d {1, 2}) / 2 (/ d {1, 2}) $ /);

If (a == null) {alert ('input parameter is not time format "); Return False;}

IF (a [1]> 24 || a [3]> 60 || a [4]> 60)

{

Alert ("time format is wrong");

Return False

}

Return True;

}

2.2 Short Date, Shape (2003-12-05)

Function StrdateTime (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]);

}

2.3 Long-term, shaped (2003-12-05 13:04:06)

Function StrdateTime (STR)

{

VAR REG = / ^ (/ D {1, 4}) (- | //) (/ D {1, 2}) / 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]);

}

2.4 Only year and month. Shape (2003-05, or 2003-5)

2.5 Only hours and minutes, like (12:03)

3, form class

3.1 All forms of the form cannot be empty

3.2 Multi-line text boxes cannot be empty.

3.3 Multi-line text boxes can not exceed SmaxStrleng

3.4 Multi-line text boxes cannot be less than SMIXStrleng

3.5 Judging whether the radio box is selected.

3.6 Judging whether the check box is selected.

3.7 All selection of checkbox, multi-selection, full number, reverse

3.8 During the file upload process, judgment file type

4, character class

4.1 The judgment character consists of a letter from A-Z or A-Z.

4.3 Judgment Character consists of letters and numbers, underscores, and points. And the beginning of the underscore and letters

/^([A-ZA-Z_]】 ([/w]*) $/g.test(Str)

4.4 String replacement function.Replace ();

5, browser class

5.1 Judging the type of browser

Window.navigator.Appname

5.2 Judging the version of IE

Window.navigator.AppVersion

5.3 Judging the resolution of the client

Window.screen.height; window.screen.width;

6, combined class

6.1 Judgment of Email.

Function ismail (Mail)

{

RETURN (/ ^ / w ((((((/ w ) | (/ w )) * / @ [A-ZA-Z0-9] (/. | -) [A-ZA-Z0- 9] ) * /. [A-ZA-Z0-9] $ /). TEST (MAIL);

}

6.2 Verification of mobile phone number

6.3 verification of ID card

Function isidcardNo (NUM)

{

IF (isnan) {alert ("Input is not a number!"); Return False;}

Var Len = Num.length, RE;

IF (len == 15)

RE = new regexp (/ ^ (/ d {6}) () (/ d {2}) (/ D {2}) (/ D {3}) $ /);

Else IF (len == 18)

RE = new regexp (/ ^ (/ d {6}) ()? (/ d {4}) (/ d {2}) (/ d {3}) (/ d) $ /)

Else {Alert ("Enter the number of digits!"); Return False;}

VAR A = Num.match (re);

IF (a! = null)

{

IF (len == 15)

{

VAR D = New Date ("19" a [3] "/" a [4] "/" a [5]);

VAR B = D.Getyear () == a [3] && (D.getMonth () 1) == a [4] && d.getdate () == a [5];

}

Else

{

VAR D = New Date (a [3] "/" a [4] "/" a [5]);

VAR B = D.Getfullyear () == a [3] && (D.getMonth () 1) == a [4] && d.getdate () == a [5];

}

IF (! b) {alert ("Enter ID" A [0] "Birthday!"); Return False;

}

Return True;

}

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

New Post(0)