Http://rayidea.net/article.asp? Id = 65
1. Regular Functions
Common javascript Functions include the following nine functions:
(1)Alert Functions: A warning dialog box is displayed, including an OK button.
(2)Confirm Function: A confirmation dialog box is displayed, including the OK and Cancel buttons.
(3)Escape Function: Converts a character to a Unicode code.
(4)Eval function: Calculates the result of an expression.
(5)IsNaN Function: The test is (true) No (false) not a number.
(6)ParseFloat Function: Converts a string to a numeric value.
(7)ParseInt Function: Converts a string to an integer (number of digits can be specified ).
(8)Prompt Function: A dialog box is displayed, 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 concatenates all elements in the array into 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: Reverse 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: Return the "Hour" part of the date. The value ranges from 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: Return 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. The value ranges from 0 ~ 11. Where 0 represents January, 2 represents March,..., 11 represents December. See the previous example.
(6) getSeconds Function: Returns the second part of the date. The value ranges from 0 ~ 59. See the previous example.
(7) getTime Function: Returns 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 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 Functions: Add the font to "1". The result is the same as that.
(3) blink Function: Causes the string to flash. The result is the same as that of the... tag.
(4) bold Functions: Make the font Bold and the results of the... tag are the same.
(5) charAt Function: Returns a specified character in a string.
(6) fixed function: Set the font to a fixed-width font. The result is the same as that of the... tag.
(7) fontcolor Function: Set the font color, which is the same as the label 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 Functions: Make the font into italics, and the results of the... tab are the same.
(11) lastIndexOf Function: Returns the index of the first subscript found in the string, starting from the right.
(12) length Function: Returns the length of a string. (No parentheses are required)
(13) link functions: Generate a hyperlink, which is equivalent to a set URL address.
(14) small Functions: Reduce the font by one, 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 Functions: Displays the string as 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
}