Javascript used in the project to determine the date and file name

Source: Internet
Author: User

String. Prototype. Trim = function ()
{
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}

String. Prototype. isint = function ()
{
If (! This) return false;
VaR STRP =/^ \ D + (\. \ D + )? $ /;
If (! STRP. Test (this) return false;
Try {
If (parseint (this )! = This) return false;
}
Catch (Ex)
{
Return false;
}
Return true;
}

Function expandorshrink (blockid, EVT ){
VaR block;
VaR event, image;
Event = EVT? EVT: (window. event? Window. Event: NULL );
Image = event. srcelement? Event. srcelement: event.tar get;
Block = Document. getelementbyid (blockid );
If (Block. style. Display = "NONE ")
{
Block. style. Display = "";
Image. src = ".../../images/arrow-up.gif ";
}
Else
{
Block. style. Display = "NONE ";
Image. src = ".../../images/arrow-down.gif ";
}
}

// Key down Function
Function is_number (){
VaR Va = event. keycode;
// A = Window. frm. interest_rate.value
If (! (Va> 47 & va <58) | (va> 95 & va <106) | (Va = 190) | (Va = 110) | (Va = 8) | (Va = 46) | (Va = 13) | (Va = 9 ))){
Event. returnvalue = 0
Return false;
}
}

Function is_int (){
VaR Va = event. keycode;
// A = Window. frm. interest_rate.value
// Event. srcelement. style. textalign = 'right'
If (! (Va> 47 & va <58) | (va> 95 & va <106) | (Va = 110) | (Va = 8) | (Va = 46) | (Va = 13) | (Va = 9 ))){
Event. returnvalue = 0
Return false;
}
}

Function isinteger (s)
{
VaR patrn =/^ [0-9] {1, 6} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function isfloat (s)
{
If (isnan (s )){
// Alert ('not a number ');
Return false;
} Else {
// Alert ('is a number ');
VaR patrn =/^ ([0-9] {}) (\. {1} [0-9] {}) $ /;
If (! Patrn.exe C (s) return false
Return true
}
}

// Yyyy-mm-dd
Function isdate (STR ){
VaR pattern =/^ (\ D {4}) | (\ D {2})-(\ D {1, 2})-(\ D {1, 2 }) $/g;
If (! Pattern. Test (STR ))
Return false;
VaR arrdate = Str. Split ("-");
If (parseint (arrdate [0], 10) <100)
Arrdate [0] = 2000 + parseint (arrdate [0], 10) + "";
VaR date = new date (arrdate [0], (parseint (arrdate [1], 10)-1) + "", arrdate [2]);
If (date. getyear () = arrdate [0]
& Date. getmonth () = (parseint (arrdate [1], 10)-1) + ""
& Date. getdate () = arrdate [2])
Return true;
Else
Return false;
}

Function isurl)
{
VaR pattern =/^ (http: \/[A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \? +!] * ([^ <> \ "\"]) *) | ([A-Za-z0-9] + \. [A-Za-z0-9] + [\/= \? % \-&_~ '@ [\] \? +!] * ([^ <> \ "\"]) *) $ /;
Return pattern.exe C (URL. tolowercase ());
}

Function isregisterusername (s)
{
VaR patrn =/^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function istruename (s)
{
VaR patrn =/^ [A-Za-Z] {1, 30} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function ispasswd (s)
{
VaR patrn =/^ (\ W) {1, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}

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.exe C (s) return false
Return true
}

Function ismobil (s)
{
VaR patrn =/^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function isemail (stremail ){
VaR myreg =/^ ([a-zA-Z0-9. _-]) + @ ([a-zA-Z0-9 _-]) + (\. [a-zA-Z0-9 _-]) + /;
If (myreg. Test (stremail) return true;
Return false;
}

Function ispostalcode (s)
{
// Var patrn =/^ [a-zA-Z0-9] {3, 12} $ /;
VaR patrn =/^ [a-zA-Z0-9] {} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function issearch (s)
{
VaR patrn =/^ [^ '~! @ # $ % ^ & * () + = |\\] [\] \{\}:;' \,. <>/?] {1} [^ '~! @ $ % ^ & () + =|\\] [\] \{\}:; '\,. <>?] {0, 19} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function isip (s) // By zergling
{
VaR patrn =/^ [0-9.] {1, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function datetimeparser (datetimestr, Format)
{
VaR year, month, day, hour, minute;
VaR date = Nan;
Try
{
Switch (Format)
{
Case "yyyy-mm-dd hh: mm ":
VaR arr = datetimestr. Split ("")
VaR ymd = arr [0]. Split ("-");
VaR Hm = arr [1]. Split (":");
Year = ymd [0];
Month = ymd [1];
Day = ymd [2];
Hour = HM [0];
Minute = HM [1];
Date = new date (year, month-1, day, hour, minute, 0 );
Break;
Default:
Break;
}
} Catch (E)
{
Return Nan;
}
Return date;
}

String. Prototype. Trim = function ()
{
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}

Function checkdatetime (datecontrolname)
{
VaR strdtcheck = eval (datecontrolname). value. Trim ();
VaR strdatestring = eval (datecontrolname). value. Trim ();
VaR strdate;
VaR strtime;
VaR strsp = 0;

If (strdatestring. Length = 0)
{Return true ;}

For (VAR I = 0; I <strdatestring. length; I ++)
{
If (strdatestring. substr (I, 1) = "")
{
Strsp = I;
Break;
}
}

If (strsp = 0)
{
If (strdtcheck. Length <= 10)
{
Strdate = strdtcheck;
Return checkdate (strdate );
}
Return false;
}
Strdate = strdatestring. substr (0, strsp );
Strtime = strdatestring. substr (strsp + 1, strdatestring. Length-strsp + 1 );

VaR separator = ':';

VaR arrayoftimes = strtime. Split (separator );

If (arrayoftimes. Length = 2)
{
Strtime = strtime + ": 00 ";
}
If (checkdate (strdate) = true)
{
If (Istime (strtime) = true)
{Return true ;}
Else
{Return false ;}
}
Else
{
Return false;
}
}

Function Istime (STR)
{
VaR A = Str. Match (/^ (\ D {1, 2 })(:)? (\ D {1, 2}) \ 2 (\ D {1, 2}) $ /);
If (A = NULL) {alert ('time format error. '); Return false ;}
If (A [1]> 24 | A [3]> 60 | A [4]> 60)
{
Alert ("Time Format error .");
Return false
}
Return true;
}

Function checkdate (sparadate)
{
If (checkyyyymmdd (sparadate) = true)
{Return true ;}

VaR strymdsp = 0;
VaR strymd;

If (! (Sparadate. substr (4,1) = "-"))
{
Return false;
}

VaR stryear = sparadate. substr (0, 4 );
Sparadate = sparadate. substr (5, sparadate. Length-5 );

For (I = 0; I <sparadate. length; I ++)
{
If (sparadate. substr (I, 1) = "-")
{
Strymdsp = I;
Break;
}
}

If (strymdsp <1)
{
Return false;
}

VaR strmonth = sparadate. substr (0, strymdsp );
VaR strday = sparadate. substr (strymdsp + 1, sparadate. Length-strymdsp + 1 );

If (strmonth. Length = 1)
{Strmonth = "0" + strmonth ;}
If (strday. Length = 1)
{Strday = "0" + strday ;}

If (checkyyyymmdd (stryear + strmonth + strday) = true)
{Return true ;}
Else
{Return false ;}

} // End function checkdate

Function checkyyyymmdd (daystring)
{

VaR digit = "0123456789 ";
Datelist = new array (, 30, 31 );
If (daystring. length! = 8) Return (false );
For (I = 0; I <8; I ++)
{
If (Digit. indexof (daystring. charat (I), 0) =-1) Return (false );
}
Year = daystring. substr (0, 4 );

Month = daystring. substr (4, 2 );

Date = daystring. substr (6, 2 );

If (Year> 2200 | year <1900 | month> 12 | month <1 | date> 31 | date <1) Return (false );
If (date> datelist [month-1]) Return (false );

Yyyy = eval (year );
If (month = "02 ")
{
If (yyyy % 400) = 0)
{
If (date> 29) Return (false );
}
Else if (yyyy % 4) = 0 & (yyyy % 100 )! = 0)
{
If (date> 29) Return (false );
}
Else
{
If (date> 28) Return (false );
}
}
Return (true );
} // End function checkyyyymmdd

// Parsedate
Function getdateobj (datestr)
{
// Alert (datestr );
VaR strdtcheck = datestr;
VaR strdatestring = datestr;
VaR strdate;
VaR strtime;
VaR strsp = 0;

For (VAR I = 0; I <strdatestring. length; I ++)
{
If (strdatestring. substr (I, 1) = "")
{
Strsp = I;
Break;
}
}
// Only date
If (strsp = 0)
{
If (strdtcheck. Length <= 10)
{
Strdate = strdtcheck;
}
Strtime = "0: 0 ";
}
Else
{
Strdate = strdatestring. substr (0, strsp );

Strtime = strdatestring. substr (strsp + 1, strdatestring. Length-strsp + 1 );

}

VaR separator = ':';

VaR arrayoftimes = strtime. Split (separator); // hh: mm: SS

If (arrayoftimes. Length = 2)
{
Strtime = strtime + ": 00 ";
}
VaR arrayofdate = strdate. Split ('-');
Arrayoftimes = strtime. Split (':');
// Alert (strdate );
// Alert (strtime );
VaR newdateobj = new date (parseint (arrayofdate [0], 10), (parseint (arrayofdate [1], 10)-1), parseint (arrayofdate [2], 10 ), parseint (arrayoftimes [0], 10), parseint (arrayoftimes [1], 10), parseint (arrayoftimes [2], 10 ));
Return newdateobj;
}

Function hasspecsymbol (STR ){
VaR I = 0;
VaR CH = '';
For (I = 0; I <Str. length; I ++ ){
Ch = Str. charat (I );
If (CH = "'") | (CH = "~ ") | (CH = "! ") | (CH =" @ ") |
(CH = "#") | (CH = "%") | (CH = "^") | (CH = "&") |
(CH = "*") | (CH = "(") | (CH = ")") | (CH = "+") |
(CH = "=") | (CH = "|") | (CH = "{") | (CH = "}") |
(CH = "[") | (CH = "]") | (CH = ":") | (CH = ";") |
(CH = "<") | (CH = ">") |
(CH = ",") | (CH = ".") | (CH = "? ")){
Return false;
}
}
Return true;
}

// Is English letter
Function ifletter (STR ){
For (VAR I = 0; I <Str. length; I ++ ){
If (parseint (Str. charcodeat (I) <27 | parseint (Str. charcodeat (I)> 128)
Return false;
}
Return true;
}

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.