Client form common verification checkform

Source: Internet
Author: User
/**//*********************************** **
*
* Client form common verification checkform (oform)
*
* Function: verifies all form elements.
*
* Usage:
* <Script language = "JavaScript" src = "check. js" type = "text/JavaScript"> </SCRIPT>
* <Form name = "form1" onsubmit = "Return checkform (this)">
* <Input type = "text" name = "ID" Check = "^/S + $" Warning = "ID cannot be blank or contain spaces">
* <Input type = "Submit">
* </Form>
*
* Verify the validity of text, password, hidden, file, textarea, select, radio, and checkbox.
*
* Regular Expression example:
* ^/S + $ cannot be blank or contain spaces
*/S {6,} is more than 6 characters long
* ^/D + $ number
* ^/D + (/./d + )? $ Number, decimal point allowed
* (. *) (/. Jpg |/. BMP) $ the file format is jpg and BMP.
* ^/D {4}/-/d {1, 2}-/d {1, 2} $
* ^ (19 | 20)/D/-(0 | 1)/D/-(0 | 1 | 2 | 3)/d $
* Date Format: 2005-5-8
* ^ 0 $ required
* ^ 0 {2,} $ select two or more
* ^ [/S |/S] {20,} $ cannot be blank, with no less than 20 words
* ^ [^/D/-_] [/W/-] * [^/-_] $ username format
* ^ [/U4e00-/u9fa5] * $ Chinese Character
* ^ [^/D/-_] [/W/-] * [^/-_] @ [^/-] [A-Za-z/D/-] * [^/-] (/. [^/-] [A-Za-z/D/-] * [^/-]) */. [A-Za-Z] {3 }(/. [A-Za-Z] {2 })? $
* Email address
*
* Regular Expression content:
* Character Description
*/Mark the next character as a special character, text, reverse reference, or octal escape character. For example, "N" matches the character "N ". "/N" matches the line break. The sequence "//" matches "/", and "/(" matches "(".
* ^ Match the start position of the input string. If the multiline attribute of the Regexp object is set, ^ matches the position after "/N" or "/R.
* $ Match the position at the end of the input string. If the multiline attribute of the Regexp object is set, $ also matches the position before "/N" or "/R.
** Match the character or subexpression zero or multiple times. For example, Zo * matches "Z" and "Zoo ". * Is equivalent to {0 ,}.
* + Match the previous character or subexpression once or multiple times. For example, "zo +" matches "zo" and "Zoo", but does not match "Z. + Is equivalent to {1 ,}.
*? Matches the previous character or subexpression zero or once. For example, "Do (ES )?" Match "do" in "do" or "does ".? It is equivalent to {0, 1 }.
* {N} n is a non-negative integer. Exactly match n times. For example, "o {2}" does not match "O" in "Bob", but matches two "O" in "food.
* {N,} n is a non-negative integer. Match at least N times. For example, "o {2,}" does not match "O" in "Bob", but matches all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'.
* {N, m} m and n are non-negative integers, where n <= m. Match at least N times and at most m times. For example, "O {1, 3}" matches the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note: you cannot insert spaces between commas and numbers.
*? When this character is followed by any other qualifier (*, + ,? , {N}, {n ,}, {n, m}), the matching mode is "non-greedy ". The "non-greedy" Mode matches the searched strings as short as possible, while the default "greedy" Mode matches the searched strings as long as possible. For example, in the string "oooo", "O + ?" Only one "O" is matched, and "O +" is matched with all "O ".
*. Match any single character except "/N. To match any character including "/N", use a mode such as "[/S.
* (Pattern) matches pattern and captures the matched subexpression. You can use the $0 $9 attribute to retrieve the captured match from the result "match" set. To match the parentheses (), use "/(" or "/)".
*(? : Pattern) a child expression that matches pattern but does not capture the matching. That is, it is a non-capturing match and is not stored for future use. This is useful for components that use the "or" character (|) combination mode. For example, compared with "Industry | industrial", "Industrial STR (? : Y | ies) is a more economical expression.
*(? = Pattern) execute the Forward prediction first search subexpression, which matches the string at the starting point of the string matching pattern. It is a non-capture match, that is, it cannot be captured for future use. For example (? = 95 | 98 | nt | 2000) "matches" Windows "in" Windows 2000 ", but does not match" Windows "in" Windows 3.1. Prediction first does not occupy characters, that is, after a match occurs, the next matched search follows the previous match, rather than after the characters that constitute prediction first.
*(?! Pattern) execute the subexpression of the reverse prediction first search, which matches the search string that is not at the start point of the string that matches the pattern. It is a non-capture match, that is, it cannot be captured for future use. For example, "windows (?! 95 | 98 | nt | 2000) "matches" windows "in" Windows 3.1 ", but does not match" windows "in" Windows 2000. Prediction first does not occupy characters, that is, after a match occurs, the next matched search follows the previous match, rather than after the characters that constitute prediction first.
* X | y matches X or Y. For example, "z | food" matches "Z" or "food. "(Z | f) Ood" matches "zood" or "food.
* [Xyz] character set. Match any character. For example, "[ABC]" matches "A" in "plain ".
* [^ XYZ] Reverse character set. Match any character that is not included. For example, "[^ ABC]" matches "P" in "plain ".
* [A-Z] character range. Matches any character in the specified range. For example, "[A-Z]" matches any lowercase letter in the range of "A" to "Z.
* [^ A-Z] character in the reverse range. Matches any character that is not within the specified range. For example, "[^ A-Z]" matches any character that is not in the range of "A" to "Z.
*/B matches a word boundary, that is, the position between the word and the space. For example, "ER/B" matches "er" in "never", but does not match "er" in "verb ".
*/B Non-word boundary match. "Er/B" matches "er" in "verb", but does not match "er" in "never ".
*/CX matches the control characters indicated by X. For example,/cm matches a control-M or carriage return character. The value of X must be between the A-Z or a-Z. If this is not the case, it is assumed that C is the "c" character itself.
*/D. It is equivalent to [0-9].
*/D: Non-numeric character match. It is equivalent to [^ 0-9].
*/F match the page feed. It is equivalent to/x0c and/Cl.
*/N line breaks match. It is equivalent to/x0a and/CJ.
*/R matches a carriage return. It is equivalent to/x0d and/cm.
*/S matches any blank characters, including spaces, tabs, and page breaks. It is equivalent to [/f/n/R/T/V.
*/S matches any non-blank characters. It is equivalent to [^/f/n/R/T/V].
*/T tab matching. It is equivalent to/x09 and/CI.
*/V vertical tab matching. It is equivalent to/x0b and/ck.
*/W matches any character type, including underscores. Equivalent to [A-Za-z0-9.
*/W any non-character match. Equivalent to [^ A-Za-z0-9.
*/XN matches n, where n is a hexadecimal escape code. The hexadecimal escape code must be exactly two digits long. For example, "/x41" matches "". "/X041" is equivalent to "/x04" & "1. ASCII code can be used in regular expressions.
*/Num matches num, where num is a positive integer. To capture matched reverse references. For example, "(.)/1" matches two consecutive identical characters.
*/N identifies an octal escape code or a reverse reference. If there are at least N capture subexpressions before/N, then n is a reverse reference. Otherwise, if n is an octal number (0-7), n is an octal escape code.
*/Nm identifies an octal escape code or reverse reference. If at least one capture subexpression exists before/nm, then nm is a reverse reference. If there are at least N captures before/nm, then n is a reverse reference, followed by M. If none of the preceding conditions exist, when N and m are Octal numbers (0-7),/nm matches the octal escape code nm.
*/NML: WHEN n is an octal number (0-3) and M and l are Octal numbers (0-7), the NML matches the octal escape code.
*/UN matches n, where n is a four-digit hexadecimal UNICODE character. For example,/u00a9 matches the copyright symbol (/u00a9 ).
*
*************************************/

// Main Function
Function checkform (oform)
{
VaR els = oform. elements;
// Traverse all Table Elements
For (VAR I = 0; I <els. length; I ++)
{
// Whether verification is required
If (ELS [I]. Check)
{
// Obtain the verified regular string
VaR sreg = els [I]. check;
// Obtain the value of the form, using a common value function
VaR sval = getvalue (ELS [I]);
// String-> regular expression, case insensitive

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.