2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.validate.web"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.validate.web"] = true;
|
|
|
3 |
dojo.provide("dojox.validate.web");
|
|
|
4 |
dojo.require("dojox.validate._base");
|
|
|
5 |
|
|
|
6 |
dojox.validate.isIpAddress = function(/*String*/value, /*Object?*/flags) {
|
|
|
7 |
// summary: Validates an IP address
|
|
|
8 |
//
|
|
|
9 |
// description:
|
|
|
10 |
// Supports 5 formats for IPv4: dotted decimal, dotted hex, dotted octal, decimal and hexadecimal.
|
|
|
11 |
// Supports 2 formats for Ipv6.
|
|
|
12 |
//
|
|
|
13 |
// value A string.
|
|
|
14 |
// flags An object. All flags are boolean with default = true.
|
|
|
15 |
// flags.allowDottedDecimal Example, 207.142.131.235. No zero padding.
|
|
|
16 |
// flags.allowDottedHex Example, 0x18.0x11.0x9b.0x28. Case insensitive. Zero padding allowed.
|
|
|
17 |
// flags.allowDottedOctal Example, 0030.0021.0233.0050. Zero padding allowed.
|
|
|
18 |
// flags.allowDecimal Example, 3482223595. A decimal number between 0-4294967295.
|
|
|
19 |
// flags.allowHex Example, 0xCF8E83EB. Hexadecimal number between 0x0-0xFFFFFFFF.
|
|
|
20 |
// Case insensitive. Zero padding allowed.
|
|
|
21 |
// flags.allowIPv6 IPv6 address written as eight groups of four hexadecimal digits.
|
|
|
22 |
// flags.allowHybrid IPv6 address written as six groups of four hexadecimal digits
|
|
|
23 |
// followed by the usual 4 dotted decimal digit notation of IPv4. x:x:x:x:x:x:d.d.d.d
|
|
|
24 |
|
|
|
25 |
var re = new RegExp("^" + dojox.regexp.ipAddress(flags) + "$", "i");
|
|
|
26 |
return re.test(value); // Boolean
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
dojox.validate.isUrl = function(/*String*/value, /*Object?*/flags) {
|
|
|
31 |
// summary: Checks if a string could be a valid URL
|
|
|
32 |
// value: A string
|
|
|
33 |
// flags: An object
|
|
|
34 |
// flags.scheme Can be true, false, or [true, false].
|
|
|
35 |
// This means: required, not allowed, or either.
|
|
|
36 |
// flags in regexp.host can be applied.
|
|
|
37 |
// flags in regexp.ipAddress can be applied.
|
|
|
38 |
// flags in regexp.tld can be applied.
|
|
|
39 |
|
|
|
40 |
var re = new RegExp("^" + dojox.regexp.url(flags) + "$", "i");
|
|
|
41 |
return re.test(value); // Boolean
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
dojox.validate.isEmailAddress = function(/*String*/value, /*Object?*/flags) {
|
|
|
45 |
// summary: Checks if a string could be a valid email address
|
|
|
46 |
//
|
|
|
47 |
// value: A string
|
|
|
48 |
// flags: An object
|
|
|
49 |
// flags.allowCruft Allow address like <mailto:foo@yahoo.com>. Default is false.
|
|
|
50 |
// flags in regexp.host can be applied.
|
|
|
51 |
// flags in regexp.ipAddress can be applied.
|
|
|
52 |
// flags in regexp.tld can be applied.
|
|
|
53 |
|
|
|
54 |
var re = new RegExp("^" + dojox.regexp.emailAddress(flags) + "$", "i");
|
|
|
55 |
return re.test(value); // Boolean
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
dojox.validate.isEmailAddressList = function(/*String*/value, /*Object?*/flags) {
|
|
|
59 |
// summary: Checks if a string could be a valid email address list.
|
|
|
60 |
//
|
|
|
61 |
// value A string.
|
|
|
62 |
// flags An object.
|
|
|
63 |
// flags.listSeparator The character used to separate email addresses. Default is ";", ",", "\n" or " ".
|
|
|
64 |
// flags in regexp.emailAddress can be applied.
|
|
|
65 |
// flags in regexp.host can be applied.
|
|
|
66 |
// flags in regexp.ipAddress can be applied.
|
|
|
67 |
// flags in regexp.tld can be applied.
|
|
|
68 |
|
|
|
69 |
var re = new RegExp("^" + dojox.regexp.emailAddressList(flags) + "$", "i");
|
|
|
70 |
return re.test(value); // Boolean
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
dojox.validate.getEmailAddressList = function(/*String*/value, /*Object?*/flags) {
|
|
|
74 |
// summary: Check if value is an email address list. If an empty list
|
|
|
75 |
// is returned, the value didn't pass the test or it was empty.
|
|
|
76 |
//
|
|
|
77 |
// value: A string
|
|
|
78 |
// flags: An object (same as dojo.validate.isEmailAddressList)
|
|
|
79 |
|
|
|
80 |
if(!flags) { flags = {}; }
|
|
|
81 |
if(!flags.listSeparator) { flags.listSeparator = "\\s;,"; }
|
|
|
82 |
|
|
|
83 |
if ( dojox.validate.isEmailAddressList(value, flags) ) {
|
|
|
84 |
return value.split(new RegExp("\\s*[" + flags.listSeparator + "]\\s*")); // Array
|
|
|
85 |
}
|
|
|
86 |
return []; // Array
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
}
|