Debian Codegraph @

dojox/validate/web.js

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