1. Regular Functions
Common javascript Functions include the following nine functions:
(1) alert function: displays a warning dialog box, including an OK button.
(2) confirm function: displays a confirmation dialog box, including the OK and Cancel buttons.
(3) escape function: converts a character to a Unicode code.
(4) eval function: calculates the result of the expression.
(5) isNaN function: test whether (true) No (false) is not a number.
(6) parseFloat function: converts a string to a number of vertices.
(7) parseInt function: converts a string to an integer number (number of digits can be specified ).
(8) prompt function: displays an input dialog box, prompting you to wait for user input. For example:
(9) unescape function: decodes characters encoded by the escape function.
2. array Functions
Javascript array functions include the following four functions:
(1) join function: converts and connects all elements in the array to a string. Example:
Program code
Function JoinDemo ()
{
Var a, B;
A = new Array (0, 1, 2, 3, 4 );
B = a. join ("-"); // delimiter
Return (B); // return B = "0-1-2-3-4"
}
(2) langth function: returns the length of the array. Example:
Program code
Function LengthDemo ()
{
Var a, l;
A = new Array (0, 1, 2, 3, 4 );
L = a. length;
Return (l); // l = 5
}
(3) reverse function: reverses the order of array elements. Example:
Program code
Function ReverseDemo ()
{
Var a, l;
A = new Array (0, 1, 2, 3, 4 );
L = a. reverse ();
Return (l );
}
(4) sort function: sorts array elements again. Example:
Program code
Function SortDemo ()
{
Var a, l;
A = new Array ("X", "y", "d", "Z", "v", "m", "r ");
L = a. sort ();
Return (l );
}
3. Date Functions
Javascript date functions include the following 20 functions:
(1) getDate function: return the "day" part of the date. The value is 1 ~ 31. Example:
Program code
Function DateDemo ()
{
Var d, s = "Today's date is :";
D = new Date ();
S + = (d. getMonth () + 1) + "/";
S + = d. getDate () + "/";
S + = d. getYear ();
Return (s );
}
(2) getDay function: returns the day of the week. The value ranges from 0 ~ 6. 0 indicates Sunday, 1 indicates Monday,..., 6 indicates Saturday. Example:
Program code
Function DateDemo ()
{
Var d, day, x, s = "Today is :";
Var x = new Array ("Sunday", "Monday", "Tuesday ");
Var x = x. concat ("Wednesday", "Thursday", "Friday ");
Var x = x. concat ("Saturday ");
D = new Date ();
Day = d. getDay ();
Return (s + = x [day]);
}
(3) getHouse function: returns the "Hour" part of the date, with a value of 0 ~ 23. Example.
Program code
Function TimeDemo ()
{
Var d, s = "The current local time is :";
Var c = ":";
D = new Date ();
S + = d. getHours () + c;
S + = d. getMinutes () + c;
S + = d. getSeconds () + c;
S + = d. getMilliseconds ();
Return (s );
}
(4) getMinutes function: returns the "Minute" part of the date. The value ranges from 0 ~ 59. See the previous example.
(5) getMonth function: return the "month" part of the date, with a value of 0 ~ 11. Where 0 represents January, 2 represents March,..., 11 represents December. See the previous example.
Child.
(6) getSeconds function: returns the "second" part of the date, with a value of 0 ~ 59. See the previous example.
(7) getTime function: return the system time.
Program code
Function GetTimeTest ()
{
Var d, s, t;
Var MinMilli = 1000*60;
Var HrMilli = MinMilli * 60;
Var DyMilli = HrMilli * 24;
D = new Date ();
T = d. getTime ();
S = "It's been"
S + = Math. round (t/DyMilli) + "days since 1/1/70 ";
Return (s );
}
(8) getTimezoneOffset function: returns the time difference between the local time and the GMT Standard Time. The unit is minute.
Program code
Function TZDemo ()
{
Var d, tz, s = "The current local time is ";
D = new Date ();
Tz = d. getTimezoneOffset ();
If (the name of tz's link point, the URL address set by another function link.
(2) big function: add the font to "1". The result is the same as that.
(3) blink function: flashes the string and returns the same result as the... tag.
(4) bold function: Make the font bold, and the results of the... tag are the same.
(5) charAt function: returns a character specified in the string.
(6) fixed function: Set the font to a fixed-width font, which is the same as the result of the... tag.
(7) fontcolor function: Set the font color, which is the same as the tag result.
(8) fontsize function: Set the font size, which is the same as the label result.
(9) indexOf function: returns the index of the first subscript found in the string, starting from the left.
(10) italics function: converts the font into italics and returns the same result as the... tag.
(11) lastIndexOf function: returns the index of the first searched subscript in the string, starting from the right.
(12) length function: returns the length of a string. (No parentheses are required)
(13) link function: generate a hyperlink, which is equivalent to a set URL address.
(14) small function: reduce the font by 1, which is the same as the result of the... tag.
(15) strike function: Add a horizontal line in the middle of the text, which is the same as the result of the... tag.
(16) sub function: displays a string as a subscript ).
(17) substring function: returns the specified characters in the string.
(18) sup function: the display string is superscript ).
(19) toLowerCase function: converts a string to lowercase.
(20) toUpperCase function: converts a string to uppercase.
// Check whether it is composed of digits
Program code
Function isDigit (s)
{
Var patrn =/^ [0-9] {1, 20} $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".
Program code
Function isRegisterUserName (s)
{
Var patrn =/^ [a-zA-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Check user name: only 1-30 strings starting with letters can be entered
Program code
Function isTrueName (s)
{
Var patrn =/^ [a-zA-Z] {1, 30} $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Password verification: only 6-20 letters, numbers, and underscores can be entered
Program code
Function isPasswd (s)
{
Var patrn =/^ (\ w) {6, 20} $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Verify the phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.
Program code
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
}
// Verify the mobile phone number. It must start with a number and can contain "-" in addition to a number.
Program code
Function isMobil (s)
{
Var patrn =/^ [+] {0, 1} (\ d) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Verify the zip code
Program code
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
}
// Verify the search keyword
Program code
Function isSearch (s)
{
Var patrn =/^ [^ '~! @ # $ % ^ & * () + = |\\] [\] \{\}:;\' \,. <>/?] {1} [^ '~! @ $ % ^ & () + =|\\] [\] \{\}:;\' \,. <>?] {0, 19} $ /;
If (! Patrn.exe c (s) return false
Return true
}
Program code
Function isIP (s) // by zergling
{
Var patrn =/^ [0-9.] {1, 20} $ /;
If (! Patrn.exe c (s) return false
Return true
}