source: Dev/branches/rest-dojo-ui/client/dojox/validate/web.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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