Common JS function

xiaoxiao2021-03-06  118

Common javascript function (a) Author: Unknown Category: HTML / JavaScript Date: 2001-11-11 21:19:11 / ************************************************************ *********************************************************** ******** EO_JSLIB.JS * JavaScript regular expression inspection ****************************************** *********************************************************** /

/ / The verification is fully composed of function isdigit (s) {var patrn = / ^ [0-9] {1, 20} $ /; if (! Patrn.exec (s)) Return Falsereturn True}

// Verify the login Name: You can only enter 5-20 letters start, can be numb, "_", "." (S) {var patrn = / ^ [A-ZA-Z] {1} ([A-ZA-Z0-9] | [._]) {4,19} $ /; if (! Patn.exec (s)) Return Falsereturn True}

// Check the user name: You can only enter 1-30 string function istruename (s) {var patrn = / ^ [a-za-z] {1, 30} $ /; if (! PATRN) .exec (s)) Return Falsereturn true}

// Calibration password: You can only enter 6-20 letters, numbers, underscore function ispasswd (s) {var patrn = / ^ (/ w) {6, 20} $ /; if (! Patrn.exec (s) Return falsereturn true}

// Check the normal phone, fax number: " " start, in addition to the digital, "-" function istel (s) {// var patrn = / ^ [ ] {0, 1} (/ d) {1,3} []? ([-]? (/ D) {1,12}) $ /; var patrn = / ^ [ ] {0, 1} (/ d) {1,3} [ ]? ([-]? ((/ d) | []) {1, 12}) $ /; if (! patrn.exec (s)) Return Falsereturn True}

// Verify the mobile number: The number must be started, in addition to the digital, "-" function ismobil (s) {var paN = / ^ [ ] {0, 1} (/ d) {1, 3} [ ]? ([-]? ((/ d) | []) {1, 12}) $ /; if (! patrn.exec (s)) Return Falsereturn True}

// Checked the Postal Code Function ISPostalcode (s) {// VAR PATRN = / ^ [A-ZA-Z0-9] {3,12} $ /; var PATRN = / ^ [A-ZA-Z0-9] {3,12} $ /; if (! Patrn.exec (s)) Return Falsereturn True}

// Check Search Keyword Function ISSearch (s) {var PATRN = / ^ [^ `~! @ # $% ^ & * () = | ///] [/] / {/}:; . , 19} $ /; if (! Patrn.exec (s)) Return Falsereturn true}

Function isip (s) // by zergling {var patrn = / ^ [0-9.] {1,20} $ /; if (! patn.exec (s)) Return Falsereturn True} / ****** *********************************************************** ********************************** Function: Isbetween * Parameters: Val As Any Value * Lo As Limit To Check * Hi As Higher Limit to Check * Calls: Nothing * Returns: True IF Val is Between Lo and Hi Both Inclusive, OtherWise False. ***************************************** *********************************************************** *** / Function Isbetween (Val, Lo, Hi) {IF ((Val Hi)) {Return (false);} else {return (true);}} / **** *********************************************************** *********************************** Function: Isdate Checks a Valid Date * Parameters: Thestr AS String * Calls: IsbetWeen, Isint * Returns: True if the a Valid Date Otherwise False. ************************************************* *************************************************************************************************************** THE1ST = thistr.indexof ('-'); var the2nd = theStr.lastIndexof ('-');

IF (THE1ST == THE2ND) {Return (false);} else {var y = thistr.Substring (0, T11st); var m = thstr.substring (THE1ST 1, THE2ND); var d = thstr.substring (the2nd 1, THESTR.LENGTH); var maxdays = 31;

IF (isint (m) == false || isint (d) == false || isint (y) == false) {return (false);} else if (Y.Length <4) {return (false); } else if (! isbetween (m, 1, 12)) {return (false);} else if (m == 4 || m == 6 || m == 9 || m == 11) MaxDays = 30 ELSE IF (M == 2) {IF (Y% 4> 0) MaxDays = 28; ELSE IF (Y% 100 == 0 && Y% 400> 0) MaxDays = 28; Else MaxDays = 29;} IF ISBETWEEN (D, 1, MaxDays) == false) {return (false);} else {return (true);}}} / ******************* *********************************************************** ************ Function: Iseudate Checks a Valid Date in British Format * Parameters: Thestr AS String * Calls: isbetween, ISINT * RETURns: TRUE IF The a Valid Date OtherWise False. *** *********************************************************** ************************************************ / Function Iseudate (thistr) {if (ISBETWEEN (THESTR.LENGTH, 8, 10) == {Return (false);} else {var the1st = thistr.indexof ('/'); var the2nd = thistr.lastIndexof ('/'); if (the1st == THE2ND) {Return (false);} else {var m = thistr.substring (THE1ST 1, T HE2ND); var d = thstr.substring (0, THE1ST); var y = thistr.substring (THE2ND 1, THESTR.LENGTH); var maxdays = 31;

IF (isint (m) == false || isint (d) == false || isint (y) == false) {return (false);} else if (Y.Length <4) {return (false); } else if (ISBETWEEN (M, 1, 12) == false) {return (false);} else if (m == 4 || m == 6 || m == 9 || m == 11) MaxDays = 30; ELSE IF (M == 2) {IF (Y% 4> 0) MAXDAYS = 28; Else IF (Y% 100 == 0 && y% 400> 0) MaxDays = 28; else maxdays = 29;}

IF (isbetween (D, 1, MaxDays) == false) {return (false);} else {return (true);}}}} / *************** *********************************************************** ************** Function: Compare Date! Which is the Latest! * Parameters: Lessdate, Moredate As String * Calls: Isdate, ISBETWEEN * RETURns: True if lessdate DATE2) {Return (false);} return (true);

}

/ ************************************************** ******************************************* Function ISEMPTY CHECKS IF * Parameter Is Empty or Null * Parameter Str As String ** *********************************************************** **************************************** / Function ISEMPTY (STR) {if ((str == null) || (STR. Length == 0)) Return True; Else Return (false);}

/ ************************************************** ***************************************** Function: Isint * Parameter: Thess String * Returns: True If the Passed Parameter IS an INTEGER, OTHERWISE FALSE * CALLS: isdigit ********************************************************** ****************************************************************************************************** Flag = true; if (ISEMPTY (THESTR)) {Flag = false;} else {for (var i = 0; i

/ ************************************************** ****************************************** Function: IsReal * Parameter: HESTR AS STRING DECLEN AS INTEGER (How Many Digits After " PERS: ISINT ************************************************************ *********************************************************** / function isreal (THESTR, DECLEN) {var dot1st = thistr.indexof ('.'); var dot2nd = theStr.lastIndexof ('.'); var ok = true;

ISEMPTY (THESTR) RETURN FALSE;

IF (DOT1ST == -1) {if (! isint (thistr)) return (false); else return (true);}

Else if (dot1st! = dot2nd) return (false); else if (dot1st == 0) Return (false); else {var intpart = thistr.substring (0, dot1st); var defpart = thistr.substring (dot2nd 1 );

IF (Decpart.Length> Declen) Return (false); Else if (! isint (INTPART) ||! isint (DECPART)) Return (false); Else IF (ISEMPTY (Decpart)) Return (false); else return True);}}

/ ************************************************** ****************************************** Function: ISEMAIL * Parameter: String (email address) * Returns: True IF the String is a valid Email address * FALSE if the passed string is not a valid Email address * EMAIL FORMAT: anyName @ EmailServer eg; webmaster@hotmail.com* @ sign can appear only once in the email address ******. *********************************************************** ********************************** / Function ISEMAIL (THESTR) {var atindex = thistr.indexof ('@'); var dotindex = theStr.Indexof ('.', atindex); var flag = true; there isub = thistr.substring (0, dotindex 1)

IF ((Atindex <1) || (atindex! = thistr.lastIndexof ('@')) || (Dotindex Document to open in the new windowhite -> Height of the new windowWide -> 1-scroll baars = yes 0-scroll bar = NORESIZE -> 1-resizable = yes 0-resizable = no * Calls: None * Returns: new window instance ************************************************************ ************************************************************************************ / Function NewWindow (DOC, Hite, Wide , Bars, Resize = "_ blank"; var opt = "Toolbar = 0, location = 0, Directories = 0, Status = 0, menubar = 0,"; OPT = ("scrollbars =" bars ", "); OPT = (" Resizable = " resize ", "); OPT = (" width = " wide ", "); opt = (" height = " hite; winrandle = window.open (DOC, Winnew, Opt); Return;} / *********************************************************** ************************************************** Function: DecimalFormat * Param Eters: Paramvalue -> Field Value * Calls: None * returns: formated string **************************************************** *********************************************************************************** DecimalFormat (paramvalue) {var intpart = parsein; var defpart = parsefloat (paramvalue) - INTPART; STR = ""; if ((Decpart == 0) || (Decpart == Null) STR = (INTPART ".00"); Else Str = (INTPART DECPART);

Return (STR);}

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

New Post(0)