DojoLib

The DojoLib library includes constants and validation functions used by the EGL Dojo widgets. The library is not a system library, and its use has prerequisites.
The prerequisites are as follows:
The library makes available the following functions:
Validators.EmailValidator(emailAddress String in, constraints Dictionary in) returns (Boolean)
Validators.EmailValidator indicates whether the first parameter represents an email address. The second parameter is a dictionary that includes a set of constraints, each of which is set to a Boolean value.

You set each key in the dictionary to a Boolean value, such that true means required, false means disallowed, and [true, false] means optional.

The following constraints are meaningful:
allowCC
Checks for the use of a country-code top-level domain. For the list of valid country codes, see the “Root Zone Database,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowCruft
Checks for the use of a mailto format. The default is false.
allowDecimal
Checks for a decimal number that ranges from 0 to 4294967295.
allowDottedDecimal
Checks for an address like 207.142.131.235, for IPv4.  No zero padding is allowed.
allowDottedHex
Checks for an address like 0x18.0x11.0x9b.0x28, for IPv4.  The value is case insensitive. Zero padding is allowed.
allowDottedOctal
Checks for an address like 0030.0021.0233.0050, for IPv4.  Zero padding is allowed.
allowGeneric
Checks for the use of generic top-level domains. For the list of valid domains, see the “Root Zone Database,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowHex
Checks for a hexadecimal number between 0x0 and 0xFFFFFFFF, for IPv4; for example, 0xCF8E83EB. The value is case insensitive. Zero padding is allowed.
allowHybrid
Checks for an IPv6 address written as six groups of four hexadecimal digits and then the usual 4 dotted decimal digit notation of IPv4. The overall format is x:x:x:x:x:x:d.d.d.d.
allowInfra
Checks for the use of an infrastructure top-level domain. The valid domain is the Address and Routing Parameter Area (ARPA) domain. For details, see “.ARPA Zone Management,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowIP
Checks for the use of a literal IP address. The default is true.
allowIPV6
Checks for an IPv6 address written as eight groups of four hexadecimal digits.
allowLocal
Checks that “localhost” is allowed. The default is false.
allowNamed
Checks that the URL can include a named host for local networks. The default is false.
allowPort
Checks that a port number is allowed. The default is true.
Here is an example invocation:
myDictionary Dictionary {allowCruft = true};
Validators.EmailValidator("mailto:you@example.com", myDictionary);
Validators.IPValidator (IPAddress String in, constraints Dictionary in) returns (Boolean)
Validators.IPValidator indicates whether the first parameter represents an IP address. The second parameter is a dictionary that includes a set of constraints, each of which is set to a Boolean value.
Here is an example invocation:
myDictionary Dictionary {allowDottedDecimal = true, allowIPV6 = false};
Validators.IPValidator("191.0.2.1", myDictionary);
The following constraints are available, with the first four for IPv4 and the last two for IPv6:
allowDecimal
Checks for a decimal number that ranges from 0 to 4294967295.
allowDottedDecimal
Checks for an address like 207.142.131.235, for IPv4.  No zero padding is allowed.
allowDottedHex
Checks for an address like 0x18.0x11.0x9b.0x28, for IPv4.  The value is case insensitive. Zero padding is allowed.
allowDottedOctal
Checks for an address like 0030.0021.0233.0050, for IPv4.  Zero padding is allowed.
allowHex
Checks for a hexadecimal number between 0x0 and 0xFFFFFFFF, for IPv4; for example, 0xCF8E83EB. The value is case insensitive. Zero padding is allowed.
allowHybrid
Checks for an IPv6 address written as six groups of four hexadecimal digits and then the usual 4 dotted decimal digit notation of IPv4. The overall format is x:x:x:x:x:x:d.d.d.d.
allowIPV6
Checks for an IPv6 address written as eight groups of four hexadecimal digits.
Validators.NumberFormatValidator (inputNumber String in, constraints Dictionary in) returns (Boolean)
Validators.NumberFormatValidator indicates whether the first parameter represents an appropriately formatted number. The second parameter is a dictionary that includes a set of constraints.
The only dictionary key is format, and the value variations are as follows:
 #       Represents a digit, 0-9.
 ?       Represents a digit, 0-9; but the digit is optional.

Other characters are as is.  

Here are examples:

     "(###) ###-####"          ->   (999) 999-9999
     "(###) ###-#### x#???" ->   (999) 9999-9999 x123

Here is an example invocation:

myDictionary Dictionary {format = "(###) ###-####"};
Validators.NumberFormatValidator("191.42", myDictionary);
Validators.PatternValidator (input String in, pattern String in) returns (Boolean)
Validators.PatternValidator indicates whether the first parameter is consistent with the second parameter, which is a regular expression. Here is an example invocation:
Validators.PatternValidator("1234", "[0-9]+");
The regular-expression rules are the ones supported by JavaScript. As noted in the following specification, the rules are based on Perl version 5:

For background information, consider Mastering Regular Expressions by Jeffrey E.F. Friedl; O'Reilly Media, August 2006, ISBN 978-0-596-52812-6.

Validators.RangeValidator (input String in, constraints Dictionary in) returns (Boolean);
Validators.RangeValidator indicates whether the first parameter is a number in the range specified by the second parameter.
The following keys are valid in the dictionary:
min
Checks that the first parameter is greater than or equal to the specified number.
max
Checks that the first parameter is less than or equal to the specified number.
decimal
Identifies the character used for the decimal point.  The default is a period.

Here is an example invocation:

myDictionary Dictionary {min = 10, max = 20};
Validators.RangeValidator("18", myDictionary);
Validators.TextValidator (input String in, constraints Dictionary in) returns (Boolean)
Validators.TextValidator indicates whether the first parameter is consistent with the second parameter.
The following keys are valid in the dictionary:
length
Checks that the number of characters in the first parameter matches the number specified here.
minlength
Checks that the number of characters in the first parameter is at least the number specified here.
maxlength
Checks that the number of characters in the first parameter is at most the number specified here.
Here is an example invocation:
myDictionary Dictionary {length = 4};
Validators.TextValidator("Four", myDictionary);
Validators.URLValidator (input String in, constraints Dictionary in) returns (Boolean)
Validators.URLValidator indicates whether the first parameter is consistent with the second parameter.
You set each key in the dictionary to a Boolean value, such that true means required, false means disallowed, and [true, false] means optional. The following keys are valid:
allowCC
Checks for the use of a country-code top-level domain. For the list of valid country codes, see the “Root Zone Database,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowDecimal
Checks for a decimal number that ranges from 0 to 4294967295.
allowDottedDecimal
Checks for an address like 207.142.131.235, for IPv4.  No zero padding is allowed.
allowDottedHex
Checks for an address like 0x18.0x11.0x9b.0x28, for IPv4.  The value is case insensitive. Zero padding is allowed.
allowDottedOctal
Checks for an address like 0030.0021.0233.0050, for IPv4.  Zero padding is allowed.
allowGeneric
Checks for the use of generic top-level domains. For the list of valid domains, see the “Root Zone Database,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowHex
Checks for a hexadecimal number between 0x0 and 0xFFFFFFFF, for IPv4; for example, 0xCF8E83EB. The value is case insensitive. Zero padding is allowed.
allowHybrid
Checks for an IPv6 address written as six groups of four hexadecimal digits and then the usual 4 dotted decimal digit notation of IPv4. The overall format is x:x:x:x:x:x:d.d.d.d.
allowInfra
Checks for the use of an infrastructure top-level domain. For details, see “.ARPA Zone Management,” which is provided by the Internet Assigned Numbers Authority (IANA).
allowIP
Checks that the URL can be a literal IP address. The default is true.
allowIPV6
Checks for an IPv6 address written as eight groups of four hexadecimal digits.
allowLocal
Checks that “localhost” is allowed. The default is false.
allowNamed
Checks that the URL can include a named host for local networks. The default is false.
allowPort
Checks that a port number is allowed. The default is true.
Here is an example invocation:
myDictionary Dictionary {};
Validators.TextValidator("", myDictionary);

You typically access those functions from a validator function; specifically, from a function that is referenced in the validators property of the DojoTextField widget.


Feedback