JavaScript verification form regular expression

xiaoxiao2021-03-06  39

// ************** Trim space ******************* //

// name: Trim

// Target: Trim Left / Right Space

// Parameter: STR

// Return: (STR)

Function Trim (STR) {

Return str.replace (/ (^ / s *) | (/ s * $) / g, "");

}

// ************* Check Number ****************** //

// Name: fucchecknum

// Target: isnumber

// Parameter: Num

// Return: is true, no false;

Function fucchecknum (num) {

VAR I, J, STRTEMP;

Strtemp = "0123456789";

IF (Num.length == 0) {

Return False;

}

For (i = 0; i

J = strtemp.indexof (Num.Charat (i));

IF (j == - 1) {

Return False;

}

}

Return True;

}

// ************* Check string ******************* //

// name: chksafe

// Target: Filter

`! @ # $% ^ & * () <>?:;" {} [] = -_ | /

// parameter: strstring

// Return: True, False;

Function Chksafe (strstring)

{

Var myreg = / [/ `/! / @ / # / $ /% / ^ / & / / * / (/) / / {/} / [/] / / = / - / _ / | //] /;

IF (MyReg.Test (strstring)) {

Return True;

}

Return False;

}

// ************* Check Date ******************* //

// name: Date

// Target: Judgement Date

// Parameter: strdate

// Return: 1,0;

Function chkdate (strdate) {

Var strough;

IF (strdate! = "")

Strlength = strdate.length;

Else

Strlength = 0;

VAR TMPY = "";

VAR TMPM = "";

VAR TMPD = ""

Var status = 0;

IF (strLength == 0) {

Return 0;

}

For (i = 0; i

IF (StRDATE.CHARAT (I) == '-') {

STATUS ;

}

IF (status> 2) {

Return 0;

}

IF ((status == 0) && (STRDATE.CHARAT (i)! = '-')) {

TMPY = TMPY STRDATE.CHARAT (I)}

IF ((status == 1) && (STRDATE.CHARAT (i)! = '-')) {

TMPM = TMPM STRDATE.CHARAT (i)

}

IF (status == 2) && (STRDATE.CHARAT (i)! = '-')) {

TMPD = TMPD STRDATE.CHARAT (i)

}

}

Year = new string (tmpy);

Month = New String (TMPM);

Day = new string (TMPD)

IF ((TMPM.LENGTH! = 4) || (TMPM.LENGTH> 2) || (TMPD.LENGTH> 2)) {

// Alert ("INVALID FORMAT OF DATE!");

Return 0;

}

IF (! (1 <= MONTH) && (12> = MONTH) && (31> = day) && (1 <= day))) {

// Alert ("INVALID MONTH OR DAY!");

Return 0;

}

IF (! (Year% 4) == 0) && (MONTH == 2) && (day == 29)) {

// Alert ("this is not a leap year!");

Return 0;

}

IF ((MONTH <= 7) && ((Month% 2) == 0) && (day> = 31)) {

// Alert ("this Month Is A Small Month!");

Return 0;

}

IF ((Month> = 8) && ((MONTH% 2) == 1) && (day> = 31)) {

// Alert ("this Month Is A Small Month!");

Return 0;

}

IF ((MONTH == 2) && (day == 30)) {

// Alert ("The Febryary NEVER HAS THIS DAY!");

Return 0;

}

Return 1;

}

// ************* ISPIC ******************* //

// name: iSPIC

// Target: Judgement Path

// Parameter: FilePath

// Return: True, False;

Function ispic (filepath) {

VAR TEMP;

VAR EXTLIST = ".jpg.gif.bmp.png";

Var the_ext = filepath.substr (FilePath.lastIndexof (".") 1) .tolowercase ();

IF (EXTLIST.INDEXOF (THE_EXT) == - 1) {

Return False;

}

Return True;

}

// ************** ChkWebsites ****************** //

// name: chkwebsites

// Target: Judgement Websites

// parameter: strWeb

// Return: True, False;

Function Chkwebs (stremail) {

Var myreg = / = (HTTP: [-9 ] ([-//a-z0-9] ([-//a-z0-9]) ([-//a-z0-9]) ([-//a-z0-9]) ([-//a-z0-9] () [A-Z0-9], 4} $ /;

IF (MyReg.Test (stres) Return True;

Return False;

}

// ************* Strlen ****************** //

// name: Strlen

// Target: Judgement Length

// Parameter: Str, Num

// Return: True, False;

Function Strlen (Str, Num) {

IF (str> num) {

Return True;

}

Return False;

}

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

New Post(0)