| 1 |
define(["doh", "../_base", "../check", "../us", "../ca", "../isbn", "../web"], function(doh, validate, check, us, ca, isbn){ |
| 2 |
|
| 3 |
doh.register("dojox.validate.tests.validate", |
| 4 |
[{ |
| 5 |
name: "isText", |
| 6 |
|
| 7 |
setUp: function(){ |
| 8 |
var localeList = ["en-us"]; |
| 9 |
for(var i = 0 ; i < localeList.length; i ++){ |
| 10 |
dojo.requireLocalization("dojo.cldr", "currency", localeList[i]); |
| 11 |
dojo.requireLocalization("dojo.cldr", "number", localeList[i]); |
| 12 |
} |
| 13 |
}, |
| 14 |
|
| 15 |
runTest: function(tests){ |
| 16 |
tests.t(isbn('0596007590')); |
| 17 |
tests.t(isbn('0-596-00759-0')); |
| 18 |
tests.f(isbn(596007590)); |
| 19 |
tests.t(isbn("960-425-059-0")); |
| 20 |
tests.t(isbn(9604250590)); |
| 21 |
tests.t(isbn('0-9752298-0-X')); |
| 22 |
tests.t(isbn('0-9752298-0-x')); |
| 23 |
tests.t(isbn('097522980x')); |
| 24 |
tests.t(isbn('097522980X')); |
| 25 |
tests.f(isbn(596007598)); |
| 26 |
tests.f(isbn('059-600759-X')); |
| 27 |
tests.f(isbn('059600')); |
| 28 |
|
| 29 |
tests.t(isbn('9780596007591')); |
| 30 |
tests.t(isbn('978-0-596 00759-1')); |
| 31 |
tests.t(isbn(9780596007591)); |
| 32 |
tests.f(isbn('978059600759X')); |
| 33 |
tests.f(isbn('978-3250-596 00759-1 ')); |
| 34 |
tests.f(isbn('3250-596 00759 ')); |
| 35 |
|
| 36 |
tests.t(validate.isText(' x')); |
| 37 |
tests.t(validate.isText('x ')); |
| 38 |
tests.t(validate.isText(' x ')); |
| 39 |
tests.f(validate.isText(' ')); |
| 40 |
tests.f(validate.isText('')); |
| 41 |
|
| 42 |
|
| 43 |
tests.t(validate.isText('123456', {length: 6} )); |
| 44 |
tests.f(validate.isText('1234567', {length: 6} )); |
| 45 |
tests.t(validate.isText('1234567', {minlength: 6} )); |
| 46 |
tests.t(validate.isText('123456', {minlength: 6} )); |
| 47 |
tests.f(validate.isText('12345', {minlength: 6} )); |
| 48 |
tests.f(validate.isText('1234567', {maxlength: 6} )); |
| 49 |
tests.t(validate.isText('123456', {maxlength: 6} )); |
| 50 |
} |
| 51 |
}, |
| 52 |
{ |
| 53 |
name: "isIpAddress", |
| 54 |
runTest: function(tests){ |
| 55 |
tests.t(validate.isIpAddress('24.17.155.40')); |
| 56 |
tests.f(validate.isIpAddress('024.17.155.040')); |
| 57 |
tests.t(validate.isIpAddress('255.255.255.255')); |
| 58 |
tests.f(validate.isIpAddress('256.255.255.255')); |
| 59 |
tests.f(validate.isIpAddress('255.256.255.255')); |
| 60 |
tests.f(validate.isIpAddress('255.255.256.255')); |
| 61 |
tests.f(validate.isIpAddress('255.255.255.256')); |
| 62 |
|
| 63 |
|
| 64 |
tests.t(validate.isIpAddress('0x18.0x11.0x9b.0x28')); |
| 65 |
tests.f(validate.isIpAddress('0x18.0x11.0x9b.0x28', {allowDottedHex: false}) ); |
| 66 |
tests.t(validate.isIpAddress('0x18.0x000000011.0x9b.0x28')); |
| 67 |
tests.t(validate.isIpAddress('0xff.0xff.0xff.0xff')); |
| 68 |
tests.f(validate.isIpAddress('0x100.0xff.0xff.0xff')); |
| 69 |
|
| 70 |
|
| 71 |
tests.t(validate.isIpAddress('0030.0021.0233.0050')); |
| 72 |
tests.f(validate.isIpAddress('0030.0021.0233.0050', {allowDottedOctal: false}) ); |
| 73 |
tests.t(validate.isIpAddress('0030.0000021.0233.00000050')); |
| 74 |
tests.t(validate.isIpAddress('0377.0377.0377.0377')); |
| 75 |
tests.f(validate.isIpAddress('0400.0377.0377.0377')); |
| 76 |
tests.f(validate.isIpAddress('0377.0378.0377.0377')); |
| 77 |
tests.f(validate.isIpAddress('0377.0377.0380.0377')); |
| 78 |
tests.f(validate.isIpAddress('0377.0377.0377.377')); |
| 79 |
|
| 80 |
|
| 81 |
tests.t(validate.isIpAddress('3482223595')); |
| 82 |
tests.t(validate.isIpAddress('0')); |
| 83 |
tests.t(validate.isIpAddress('4294967295')); |
| 84 |
tests.f(validate.isIpAddress('4294967296')); |
| 85 |
tests.f(validate.isIpAddress('3482223595', {allowDecimal: false})); |
| 86 |
|
| 87 |
|
| 88 |
tests.t(validate.isIpAddress('0xCF8E83EB')); |
| 89 |
tests.t(validate.isIpAddress('0x0')); |
| 90 |
tests.t(validate.isIpAddress('0x00ffffffff')); |
| 91 |
tests.f(validate.isIpAddress('0x100000000')); |
| 92 |
tests.f(validate.isIpAddress('0xCF8E83EB', {allowHex: false})); |
| 93 |
|
| 94 |
|
| 95 |
tests.t(validate.isIpAddress('fedc:BA98:7654:3210:FEDC:BA98:7654:3210')); |
| 96 |
tests.t(validate.isIpAddress('1080:0:0:0:8:800:200C:417A')); |
| 97 |
tests.f(validate.isIpAddress('1080:0:0:0:8:800:200C:417A', {allowIPv6: false})); |
| 98 |
|
| 99 |
|
| 100 |
tests.t(validate.isIpAddress('0:0:0:0:0:0:13.1.68.3')); |
| 101 |
tests.t(validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38')); |
| 102 |
tests.f(validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38', {allowHybrid: false})); |
| 103 |
|
| 104 |
} |
| 105 |
}, |
| 106 |
{ |
| 107 |
name: "isUrlTest", |
| 108 |
runTest: function(tests){ |
| 109 |
|
| 110 |
tests.t(validate.isUrl('www.yahoo.com')); |
| 111 |
tests.t(validate.isUrl('http://www.yahoo.com')); |
| 112 |
tests.t(validate.isUrl('https://www.yahoo.com')); |
| 113 |
tests.f(validate.isUrl('http://.yahoo.com')); |
| 114 |
tests.f(validate.isUrl('http://www.-yahoo.com')); |
| 115 |
tests.f(validate.isUrl('http://www.yahoo-.com')); |
| 116 |
tests.t(validate.isUrl('http://y-a---h-o-o.com')); |
| 117 |
tests.t(validate.isUrl('http://www.y.com')); |
| 118 |
tests.t(validate.isUrl('http://www.yahoo.museum')); |
| 119 |
tests.t(validate.isUrl('http://www.yahoo.co.uk')); |
| 120 |
tests.f(validate.isUrl('http://www.micro$oft.com')); |
| 121 |
|
| 122 |
tests.t(validate.isUrl('http://www.y.museum:8080')); |
| 123 |
tests.t(validate.isUrl('http://12.24.36.128:8080')); |
| 124 |
tests.f(validate.isUrl('http://12.24.36.128:8080', {allowIP: false} )); |
| 125 |
tests.t(validate.isUrl('www.y.museum:8080')); |
| 126 |
tests.f(validate.isUrl('www.y.museum:8080', {scheme: true} )); |
| 127 |
tests.t(validate.isUrl('localhost:8080', {allowLocal: true} )); |
| 128 |
tests.f(validate.isUrl('localhost:8080', {} )); |
| 129 |
tests.t(validate.isUrl('http://www.yahoo.com/index.html?a=12&b=hello%20world#anchor')); |
| 130 |
tests.t(validate.isUrl('http://www.yahoo.xyz')); |
| 131 |
tests.t(validate.isUrl('http://www.yahoo.com/index.html#anchor')); |
| 132 |
tests.t(validate.isUrl('http://cocoon.apache.org/2.1/')); |
| 133 |
} |
| 134 |
}, |
| 135 |
{ |
| 136 |
name: "isEmailAddress", |
| 137 |
runTest: function(tests) { |
| 138 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 139 |
tests.f(validate.isEmailAddress('x@yahoo')); |
| 140 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 141 |
tests.f(validate.isEmailAddress('[email protected]')); |
| 142 |
tests.f(validate.isEmailAddress('[email protected]')); |
| 143 |
tests.f(validate.isEmailAddress('[email protected]')); |
| 144 |
tests.t(validate.isEmailAddress('azAZ09!#$%.&\'*+-/=?_`{|}[email protected]')); |
| 145 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 146 |
tests.f(validate.isEmailAddress('x([email protected]')); |
| 147 |
tests.f(validate.isEmailAddress('x)[email protected]')); |
| 148 |
tests.f(validate.isEmailAddress('x<[email protected]')); |
| 149 |
tests.f(validate.isEmailAddress('x>[email protected]')); |
| 150 |
tests.f(validate.isEmailAddress('x[[email protected]')); |
| 151 |
tests.f(validate.isEmailAddress('x][email protected]')); |
| 152 |
tests.f(validate.isEmailAddress('x:[email protected]')); |
| 153 |
tests.f(validate.isEmailAddress('x;[email protected]')); |
| 154 |
tests.f(validate.isEmailAddress('x@[email protected]')); |
| 155 |
tests.f(validate.isEmailAddress('x\\[email protected]')); |
| 156 |
tests.f(validate.isEmailAddress('x,[email protected]')); |
| 157 |
tests.f(validate.isEmailAddress('x\"[email protected]')); |
| 158 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 159 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 160 |
tests.t(validate.isEmailAddress('[email protected]')); |
| 161 |
tests.t(validate.isEmailAddress("o'[email protected]")); |
| 162 |
tests.t(validate.isEmailAddress("o''[email protected]")); |
| 163 |
tests.t(validate.isEmailAddress("'[email protected]")); |
| 164 |
tests.t(validate.isEmailAddress("fred&[email protected]")); |
| 165 |
tests.t(validate.isEmailAddress("fred&&[email protected]")); |
| 166 |
|
| 167 |
|
| 168 |
tests.t(validate.isEmailAddress("fred&barney@localhost", {allowLocal: true} )); |
| 169 |
tests.f(validate.isEmailAddress("fred&barney@localhost")); |
| 170 |
|
| 171 |
|
| 172 |
tests.t(validate.isEmailAddress("mailto:fred&[email protected]", {allowCruft: true} )); |
| 173 |
tests.t(validate.isEmailAddress("<fred&[email protected]>", {allowCruft: true} )); |
| 174 |
tests.f(validate.isEmailAddress("mailto:fred&[email protected]")); |
| 175 |
tests.f(validate.isEmailAddress("<fred&[email protected]>")); |
| 176 |
|
| 177 |
|
| 178 |
tests.t(validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true, allowCruft: true} )); |
| 179 |
tests.f(validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowCruft: true} )); |
| 180 |
tests.f(validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true} )); |
| 181 |
} |
| 182 |
}, |
| 183 |
{ |
| 184 |
name: "isEmailsAddressList", |
| 185 |
runTest: function(tests) { |
| 186 |
tests.t(validate.isEmailAddressList( |
| 187 |
"[email protected] \n [email protected] ; o'[email protected] , fred&[email protected] \n" ) |
| 188 |
); |
| 189 |
tests.t(validate.isEmailAddressList( |
| 190 |
"[email protected] \n x.y.z.w@localhost \n o'[email protected] \n fred&barney@localhost", |
| 191 |
{allowLocal: true} ) |
| 192 |
); |
| 193 |
tests.f(validate.isEmailAddressList( |
| 194 |
"[email protected]; x.y.z.w@localhost; o'[email protected]; fred&barney@localhost", {listSeparator: ";"} ) |
| 195 |
); |
| 196 |
tests.t(validate.isEmailAddressList( |
| 197 |
"mailto:[email protected]; <[email protected]>; <mailto:o'[email protected]>; fred&[email protected]", |
| 198 |
{allowCruft: true, listSeparator: ";"} ) |
| 199 |
); |
| 200 |
tests.f(validate.isEmailAddressList( |
| 201 |
"mailto:[email protected]; <[email protected]>; <mailto:o'[email protected]>; fred&[email protected]", |
| 202 |
{listSeparator: ";"} ) |
| 203 |
); |
| 204 |
tests.t(validate.isEmailAddressList( |
| 205 |
"mailto:[email protected]; <x.y.z.w@localhost>; <mailto:o'mally@localhost>; fred&barney@localhost", |
| 206 |
{allowLocal: true, allowCruft: true, listSeparator: ";"} ) |
| 207 |
); |
| 208 |
} |
| 209 |
}, |
| 210 |
{ |
| 211 |
name: "getEmailAddressList", |
| 212 |
runTest: function(tests) { |
| 213 |
var list = "[email protected] \n [email protected] ; o'[email protected] , fred&[email protected]"; |
| 214 |
tests.is(4, validate.getEmailAddressList(list).length); |
| 215 |
|
| 216 |
var localhostList = "[email protected]; x.y.z.w@localhost; o'[email protected]; fred&barney@localhost"; |
| 217 |
tests.is(0, validate.getEmailAddressList(localhostList).length); |
| 218 |
tests.is(4, validate.getEmailAddressList(localhostList, {allowLocal: true} ).length); |
| 219 |
} |
| 220 |
}, |
| 221 |
{ |
| 222 |
name: "isInRangeInt", |
| 223 |
runTest: function(tests) { |
| 224 |
|
| 225 |
tests.f(validate.isInRange( '0', {min: 1, max: 100} )); |
| 226 |
tests.t(validate.isInRange( '1', {min: 1, max: 100} )); |
| 227 |
tests.f(validate.isInRange( '-50', {min: 1, max: 100} )); |
| 228 |
|
| 229 |
tests.t(validate.isInRange( '100', {min: 1, max: 100} )); |
| 230 |
tests.f(validate.isInRange( '101', {min: 1, max: 100} )); |
| 231 |
} |
| 232 |
}, |
| 233 |
{ |
| 234 |
name:"isInRangeReal", |
| 235 |
runTest: function(tests){ |
| 236 |
|
| 237 |
tests.f(validate.isInRange( '0.9', {min: 1.0, max: 10.0, locale: 'en-us'} )); |
| 238 |
tests.t(validate.isInRange( '1.0', {min: 1.0, max: 10.0, locale: 'en-us'} )); |
| 239 |
tests.f(validate.isInRange( '-5.0', {min: 1.0, max: 10.0, locale: 'en-us'} )); |
| 240 |
|
| 241 |
tests.t(validate.isInRange( '10.0', {min: 1.0, max: 10.0, locale: 'en-us'} )); |
| 242 |
tests.f(validate.isInRange( '10.1', {min: 1.0, max: 10.0, locale: 'en-us'} )); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
tests.t(validate.isInRange('1,500,000', { min: 0, locale: 'en-us'})); |
| 250 |
tests.f(validate.isInRange('1,500,000', { min: 1000, max: 20000, locale: 'en-us'})); |
| 251 |
} |
| 252 |
}, |
| 253 |
{ |
| 254 |
name: "isUsPhoneNumber", |
| 255 |
runTest: function(tests) { |
| 256 |
tests.t(us.isPhoneNumber('(111) 111-1111')); |
| 257 |
tests.t(us.isPhoneNumber('(111) 111 1111')); |
| 258 |
tests.t(us.isPhoneNumber('111 111 1111')); |
| 259 |
tests.t(us.isPhoneNumber('111.111.1111')); |
| 260 |
tests.t(us.isPhoneNumber('111-111-1111')); |
| 261 |
tests.t(us.isPhoneNumber('111/111-1111')); |
| 262 |
tests.f(us.isPhoneNumber('111 111-1111')); |
| 263 |
tests.f(us.isPhoneNumber('111-1111')); |
| 264 |
tests.f(us.isPhoneNumber('(111)-111-1111')); |
| 265 |
|
| 266 |
|
| 267 |
tests.t(us.isPhoneNumber('111-111-1111 x1')); |
| 268 |
tests.t(us.isPhoneNumber('111-111-1111 x12')); |
| 269 |
tests.t(us.isPhoneNumber('111-111-1111 x1234')); |
| 270 |
} |
| 271 |
}, |
| 272 |
{ |
| 273 |
name: "isUsSocialSecurityNumber", |
| 274 |
runTest: function(tests) { |
| 275 |
tests.t(us.isSocialSecurityNumber('123-45-6789')); |
| 276 |
tests.t(us.isSocialSecurityNumber('123 45 6789')); |
| 277 |
tests.t(us.isSocialSecurityNumber('123456789')); |
| 278 |
tests.f(us.isSocialSecurityNumber('123-45 6789')); |
| 279 |
tests.f(us.isSocialSecurityNumber('12345 6789')); |
| 280 |
tests.f(us.isSocialSecurityNumber('123-456789')); |
| 281 |
} |
| 282 |
}, |
| 283 |
{ |
| 284 |
name:"isUsZipCode", |
| 285 |
runTest: function(tests) { |
| 286 |
tests.t(us.isZipCode('12345-6789')); |
| 287 |
tests.t(us.isZipCode('12345 6789')); |
| 288 |
tests.t(us.isZipCode('123456789')); |
| 289 |
tests.t(us.isZipCode('12345')); |
| 290 |
} |
| 291 |
}, |
| 292 |
{ |
| 293 |
name:"isCaZipCode", |
| 294 |
runTest: function(tests) { |
| 295 |
tests.t(ca.isPostalCode('A1Z 3F3')); |
| 296 |
tests.f(ca.isPostalCode('1AZ 3F3')); |
| 297 |
tests.t(ca.isPostalCode('a1z 3f3')); |
| 298 |
tests.f(ca.isPostalCode('xxxxxx')); |
| 299 |
tests.f(ca.isPostalCode('A1Z3F3')); |
| 300 |
|
| 301 |
} |
| 302 |
}, |
| 303 |
{ |
| 304 |
name:"isUsState", |
| 305 |
runTest: function(tests) { |
| 306 |
tests.t(us.isState('CA')); |
| 307 |
tests.t(us.isState('ne')); |
| 308 |
tests.t(us.isState('PR')); |
| 309 |
tests.f(us.isState('PR', {allowTerritories: false} )); |
| 310 |
tests.t(us.isState('AA')); |
| 311 |
tests.f(us.isState('AA', {allowMilitary: false} )); |
| 312 |
} |
| 313 |
} |
| 314 |
]); |
| 315 |
|
| 316 |
}); |