How to use validate method in taiko

Best JavaScript code snippet using taiko

validation.test.js

Source:validation.test.js Github

copy

Full Screen

1/**2 * Copyright © Magento, Inc. All rights reserved.3 * See COPYING.txt for license details.4 */5define([6 'jquery',7 'mage/validation'8], function ($) {9 'use strict';10 describe('Testing credit card validation', function () {11 it('Card type matches credit card number', function () {12 expect($.validator.methods['validate-cc-type-select'].call(13 this, 'VI', null, $('<input id="visa-valid" type="text" value="4916808263499650"/>'))14 ).toEqual(true);15 expect($.validator.methods['validate-cc-type-select'].call(16 this, 'VI', null, $('<input id="visa-invalid" type="text" value="1234567890123456"/>'))17 ).toEqual(false);18 expect($.validator.methods['validate-cc-type-select'].call(19 this, 'MC', null, $('<input id="mc-valid" type="text" value="5203731841177490"/>'))20 ).toEqual(true);21 expect($.validator.methods['validate-cc-type-select'].call(22 this, 'MC', null, $('<input id="mc-invalid" type="text" value="1111222233334444"/>'))23 ).toEqual(false);24 expect($.validator.methods['validate-cc-type-select'].call(25 this, 'MC', null, $('<input id="mc-valid" type="text" value="2221220000000003"/>'))26 ).toEqual(true);27 expect($.validator.methods['validate-cc-type-select'].call(28 this, 'MC', null, $('<input id="mc-invalid" type="text" value="2721220000000008"/>'))29 ).toEqual(false);30 expect($.validator.methods['validate-cc-type-select'].call(31 this, 'AE', null, $('<input id="ae-valid" type="text" value="376244899619217"/>'))32 ).toEqual(true);33 expect($.validator.methods['validate-cc-type-select'].call(34 this, 'AE', null, $('<input id="ae-invalid" type="text" value="123451234512345"/>'))35 ).toEqual(false);36 expect($.validator.methods['validate-cc-type-select'].call(37 this, 'DI', null, $('<input id="di-valid" type="text" value="601109020000000003"/>'))38 ).toEqual(true);39 expect($.validator.methods['validate-cc-type-select'].call(40 this, 'DI', null, $('<input id="di-invalid" type="text" value="6011111144444444"/>'))41 ).toEqual(false);42 expect($.validator.methods['validate-cc-type-select'].call(43 this, 'DI', null, $('<input id="di-valid" type="text" value="6011222233334444"/>'))44 ).toEqual(true);45 expect($.validator.methods['validate-cc-type-select'].call(46 this, 'DI', null, $('<input id="di-invalid" type="text" value="6011522233334447"/>'))47 ).toEqual(false);48 expect($.validator.methods['validate-cc-type-select'].call(49 this, 'DI', null, $('<input id="di-valid" type="text" value="601174455555553"/>'))50 ).toEqual(true);51 expect($.validator.methods['validate-cc-type-select'].call(52 this, 'DI', null, $('<input id="di-invalid" type="text" value="6011755555555550"/>'))53 ).toEqual(false);54 expect($.validator.methods['validate-cc-type-select'].call(55 this, 'DI', null, $('<input id="di-valid" type="text" value="601177455555556"/>'))56 ).toEqual(true);57 expect($.validator.methods['validate-cc-type-select'].call(58 this, 'DI', null, $('<input id="di-invalid" type="text" value="601182455555556"/>'))59 ).toEqual(false);60 expect($.validator.methods['validate-cc-type-select'].call(61 this, 'DI', null, $('<input id="di-valid" type="text" value="601187999555558"/>'))62 ).toEqual(true);63 expect($.validator.methods['validate-cc-type-select'].call(64 this, 'DI', null, $('<input id="di-invalid" type="text" value="601287999555556"/>'))65 ).toEqual(false);66 expect($.validator.methods['validate-cc-type-select'].call(67 this, 'DI', null, $('<input id="di-valid" type="text" value="6444444444444443"/>'))68 ).toEqual(true);69 expect($.validator.methods['validate-cc-type-select'].call(70 this, 'DI', null, $('<input id="di-invalid" type="text" value="6644444444444441"/>'))71 ).toEqual(false);72 expect($.validator.methods['validate-cc-type-select'].call(73 this, 'DN', null, $('<input id="dn-valid" type="text" value="3095434000000001"/>'))74 ).toEqual(true);75 expect($.validator.methods['validate-cc-type-select'].call(76 this, 'DN', null, $('<input id="dn-invalid" type="text" value="3799999900000003"/>'))77 ).toEqual(false);78 expect($.validator.methods['validate-cc-type-select'].call(79 this, 'DN', null, $('<input id="dn-valid" type="text" value="3044444444444444"/>'))80 ).toEqual(true);81 expect($.validator.methods['validate-cc-type-select'].call(82 this, 'DN', null, $('<input id="dn-invalid" type="text" value="3064444444444449"/>'))83 ).toEqual(false);84 expect($.validator.methods['validate-cc-type-select'].call(85 this, 'DN', null, $('<input id="dn-valid" type="text" value="3095444444444442"/>'))86 ).toEqual(true);87 expect($.validator.methods['validate-cc-type-select'].call(88 this, 'DN', null, $('<input id="dn-invalid" type="text" value="3096444444444441"/>'))89 ).toEqual(false);90 expect($.validator.methods['validate-cc-type-select'].call(91 this, 'DN', null, $('<input id="dn-valid" type="text" value="3696444444444445"/>'))92 ).toEqual(true);93 expect($.validator.methods['validate-cc-type-select'].call(94 this, 'DN', null, $('<input id="dn-invalid" type="text" value="3796444444444444"/>'))95 ).toEqual(false);96 expect($.validator.methods['validate-cc-type-select'].call(97 this, 'DN', null, $('<input id="dn-valid" type="text" value="3696444444444445"/>'))98 ).toEqual(true);99 expect($.validator.methods['validate-cc-type-select'].call(100 this, 'DN', null, $('<input id="dn-valid" type="text" value="3896444444444443"/>'))101 ).toEqual(true);102 expect($.validator.methods['validate-cc-type-select'].call(103 this, 'DN', null, $('<input id="dn-invalid" type="text" value="3796444444444444"/>'))104 ).toEqual(false);105 expect($.validator.methods['validate-cc-type-select'].call(106 this, 'JCB', null, $('<input id="jcb-valid" type="text" value="3528444444444449"/>'))107 ).toEqual(true);108 expect($.validator.methods['validate-cc-type-select'].call(109 this, 'JCB', null, $('<input id="jcb-invalid" type="text" value="3527444444444448"/>'))110 ).toEqual(false);111 expect($.validator.methods['validate-cc-type-select'].call(112 this, 'JCB', null, $('<input id="jcb-invalid" type="text" value="3590444444444448"/>'))113 ).toEqual(false);114 expect($.validator.methods['validate-cc-type-select'].call(115 this, 'UN', null, $('<input id="un-valid" type="text" value="6221262244444440"/>'))116 ).toEqual(true);117 expect($.validator.methods['validate-cc-type-select'].call(118 this, 'UN', null, $('<input id="un-invalid" type="text" value="6229981111111111"/>'))119 ).toEqual(false);120 expect($.validator.methods['validate-cc-type-select'].call(121 this, 'UN', null, $('<input id="un-valid" type="text" value="6249981111111117"/>'))122 ).toEqual(true);123 expect($.validator.methods['validate-cc-type-select'].call(124 this, 'UN', null, $('<input id="un-invalid" type="text" value="6279981111111110"/>'))125 ).toEqual(false);126 expect($.validator.methods['validate-cc-type-select'].call(127 this, 'UN', null, $('<input id="un-valid" type="text" value="6282981111111115"/>'))128 ).toEqual(true);129 expect($.validator.methods['validate-cc-type-select'].call(130 this, 'UN', null, $('<input id="un-invalid" type="text" value="6289981111111118"/>'))131 ).toEqual(false);132 });133 });134 describe('Testing UK Mobile number validation', function () {135 it('Valid UK Mobile Number', function () {136 var element = $('<input id="telephone" type="text" value="07400123456" />');137 expect($.validator.methods.mobileUK.call(138 $.validator.prototype, element.val(), element.get(0)139 )).toBeTruthy();140 });141 it('Invalid UK Mobile Number', function () {142 var element = $('<input id="telephone" type="text" value="06400123456" />');143 expect($.validator.methods.mobileUK.call(144 $.validator.prototype, element.val(), element.get(0)145 )).toBeFalsy();146 });147 it('Valid UK Mobile Number (International)', function () {148 var element = $('<input id="telephone" type="text" value="+447400123456" />');149 expect($.validator.methods.mobileUK.call(150 $.validator.prototype, element.val(), element.get(0)151 )).toBeTruthy();152 });153 it('Invalid UK Mobile Number', function () {154 var element = $('<input id="telephone" type="text" value="+446400123456" />');155 expect($.validator.methods.mobileUK.call(156 $.validator.prototype, element.val(), element.get(0)157 )).toBeFalsy();158 });159 });160 describe('Validation of the password against the user name', function () {161 it('rejects data, if password is the same as user name', function () {162 var password = $('<input id="password" type="password" value="EmailPasswordTheSame" />'),163 email = $('<input id="email" type="email" value="EmailPasswordTheSame" />');164 expect($.validator.methods['password-not-equal-to-user-name'].call(165 $.validator.prototype, password.val(), null, email.val()166 )).toEqual(false);167 });168 it('approves data, if password is different from user name', function () {169 var password = $('<input id="password" type="password" value="SomePassword" />'),170 email = $('<input id="email" type="email" value="SomeEmail" />');171 expect($.validator.methods['password-not-equal-to-user-name'].call(172 $.validator.prototype, password.val(), null, email.val()173 )).toEqual(true);174 });175 });176 describe('Testing validate-no-html-tags', function () {177 it('validate-no-html-tags', function () {178 expect($.validator.methods['validate-no-html-tags']179 .call($.validator.prototype, '')).toEqual(true);180 expect($.validator.methods['validate-no-html-tags']181 .call($.validator.prototype, null)).toEqual(true);182 expect($.validator.methods['validate-no-html-tags']183 .call($.validator.prototype, 'abc')).toEqual(true);184 expect($.validator.methods['validate-no-html-tags']185 .call($.validator.prototype, '<div>abc</div>')).toEqual(false);186 });187 });188 describe('Testing allow-container-className', function () {189 it('allow-container-className', function () {190 var radio = $('<input type="radio" class="change-container-classname"/>'),191 checkbox = $('<input type="checkbox" class="change-container-classname"/>'),192 radio2 = $('<input type="radio"/>'),193 checkbox2 = $('<input type="checkbox"/>');194 expect($.validator.methods['allow-container-className']195 .call($.validator.prototype, radio[0])).toEqual(true);196 expect($.validator.methods['allow-container-className']197 .call($.validator.prototype, checkbox[0])).toEqual(true);198 expect($.validator.methods['allow-container-className']199 .call($.validator.prototype, radio2[0])).toEqual(false);200 expect($.validator.methods['allow-container-className']201 .call($.validator.prototype, checkbox2[0])).toEqual(false);202 });203 });204 describe('Testing validate-select', function () {205 it('validate-select', function () {206 expect($.validator.methods['validate-select']207 .call($.validator.prototype, '')).toEqual(false);208 expect($.validator.methods['validate-select']209 .call($.validator.prototype, 'none')).toEqual(false);210 expect($.validator.methods['validate-select']211 .call($.validator.prototype, null)).toEqual(false);212 expect($.validator.methods['validate-select']213 .call($.validator.prototype, undefined)).toEqual(false);214 expect($.validator.methods['validate-select']215 .call($.validator.prototype, 'abc')).toEqual(true);216 });217 });218 describe('Testing validate-no-empty', function () {219 it('validate-no-empty', function () {220 expect($.validator.methods['validate-no-empty']221 .call($.validator.prototype, '')).toEqual(false);222 expect($.validator.methods['validate-no-empty']223 .call($.validator.prototype, null)).toEqual(false);224 expect($.validator.methods['validate-no-empty']225 .call($.validator.prototype, undefined)).toEqual(false);226 expect($.validator.methods['validate-no-empty']227 .call($.validator.prototype, ' ')).toEqual(false);228 expect($.validator.methods['validate-no-empty']229 .call($.validator.prototype, 'test')).toEqual(true);230 });231 });232 describe('Testing validate-alphanum-with-spaces', function () {233 it('validate-alphanum-with-spaces', function () {234 expect($.validator.methods['validate-alphanum-with-spaces']235 .call($.validator.prototype, '')).toEqual(true);236 expect($.validator.methods['validate-alphanum-with-spaces']237 .call($.validator.prototype, null)).toEqual(true);238 expect($.validator.methods['validate-alphanum-with-spaces']239 .call($.validator.prototype, undefined)).toEqual(true);240 expect($.validator.methods['validate-alphanum-with-spaces']241 .call($.validator.prototype, ' ')).toEqual(true);242 expect($.validator.methods['validate-alphanum-with-spaces']243 .call($.validator.prototype, 'abc ')).toEqual(true);244 expect($.validator.methods['validate-alphanum-with-spaces']245 .call($.validator.prototype, ' 123 ')).toEqual(true);246 expect($.validator.methods['validate-alphanum-with-spaces']247 .call($.validator.prototype, ' abc123 ')).toEqual(true);248 expect($.validator.methods['validate-alphanum-with-spaces']249 .call($.validator.prototype, ' !@# ')).toEqual(false);250 expect($.validator.methods['validate-alphanum-with-spaces']251 .call($.validator.prototype, ' abc.123 ')).toEqual(false);252 });253 });254 describe('Testing validate-phoneStrict', function () {255 it('validate-phoneStrict', function () {256 expect($.validator.methods['validate-phoneStrict']257 .call($.validator.prototype, '')).toEqual(true);258 expect($.validator.methods['validate-phoneStrict']259 .call($.validator.prototype, null)).toEqual(true);260 expect($.validator.methods['validate-phoneStrict']261 .call($.validator.prototype, undefined)).toEqual(true);262 expect($.validator.methods['validate-phoneStrict']263 .call($.validator.prototype, ' ')).toEqual(false);264 expect($.validator.methods['validate-phoneStrict']265 .call($.validator.prototype, '5121231234')).toEqual(false);266 expect($.validator.methods['validate-phoneStrict']267 .call($.validator.prototype, '512.123.1234')).toEqual(false);268 expect($.validator.methods['validate-phoneStrict']269 .call($.validator.prototype, '512-123-1234')).toEqual(true);270 expect($.validator.methods['validate-phoneStrict']271 .call($.validator.prototype, '(512)123-1234')).toEqual(true);272 expect($.validator.methods['validate-phoneStrict']273 .call($.validator.prototype, '(512) 123-1234')).toEqual(true);274 });275 });276 describe('Testing validate-phoneLax', function () {277 it('validate-phoneLax', function () {278 expect($.validator.methods['validate-phoneLax']279 .call($.validator.prototype, '')).toEqual(true);280 expect($.validator.methods['validate-phoneLax']281 .call($.validator.prototype, null)).toEqual(true);282 expect($.validator.methods['validate-phoneLax']283 .call($.validator.prototype, undefined)).toEqual(true);284 expect($.validator.methods['validate-phoneLax']285 .call($.validator.prototype, ' ')).toEqual(false);286 expect($.validator.methods['validate-phoneLax']287 .call($.validator.prototype, '5121231234')).toEqual(true);288 expect($.validator.methods['validate-phoneLax']289 .call($.validator.prototype, '512.123.1234')).toEqual(true);290 expect($.validator.methods['validate-phoneLax']291 .call($.validator.prototype, '512-123-1234')).toEqual(true);292 expect($.validator.methods['validate-phoneLax']293 .call($.validator.prototype, '(512)123-1234')).toEqual(true);294 expect($.validator.methods['validate-phoneLax']295 .call($.validator.prototype, '(512) 123-1234')).toEqual(true);296 expect($.validator.methods['validate-phoneLax']297 .call($.validator.prototype, '(512)1231234')).toEqual(true);298 expect($.validator.methods['validate-phoneLax']299 .call($.validator.prototype, '(512)_123_1234')).toEqual(false);300 });301 });302 describe('Testing validate-fax', function () {303 it('validate-fax', function () {304 expect($.validator.methods['validate-fax']305 .call($.validator.prototype, '')).toEqual(true);306 expect($.validator.methods['validate-fax']307 .call($.validator.prototype, null)).toEqual(true);308 expect($.validator.methods['validate-fax']309 .call($.validator.prototype, undefined)).toEqual(true);310 expect($.validator.methods['validate-fax']311 .call($.validator.prototype, ' ')).toEqual(false);312 expect($.validator.methods['validate-fax']313 .call($.validator.prototype, '5121231234')).toEqual(false);314 expect($.validator.methods['validate-fax']315 .call($.validator.prototype, '512.123.1234')).toEqual(false);316 expect($.validator.methods['validate-fax']317 .call($.validator.prototype, '512-123-1234')).toEqual(true);318 expect($.validator.methods['validate-fax']319 .call($.validator.prototype, '(512)123-1234')).toEqual(true);320 expect($.validator.methods['validate-fax']321 .call($.validator.prototype, '(512) 123-1234')).toEqual(true);322 });323 });324 describe('Testing validate-email', function () {325 it('validate-email', function () {326 expect($.validator.methods['validate-email']327 .call($.validator.prototype, '')).toEqual(true);328 expect($.validator.methods['validate-email']329 .call($.validator.prototype, null)).toEqual(true);330 expect($.validator.methods['validate-email']331 .call($.validator.prototype, undefined)).toEqual(true);332 expect($.validator.methods['validate-email']333 .call($.validator.prototype, ' ')).toEqual(false);334 expect($.validator.methods['validate-email']335 .call($.validator.prototype, '123@123.com')).toEqual(true);336 expect($.validator.methods['validate-email']337 .call($.validator.prototype, 'abc@124.en')).toEqual(true);338 expect($.validator.methods['validate-email']339 .call($.validator.prototype, 'abc@abc.commmmm')).toEqual(true);340 expect($.validator.methods['validate-email']341 .call($.validator.prototype, 'abc.abc.abc@abc.commmmm')).toEqual(true);342 expect($.validator.methods['validate-email']343 .call($.validator.prototype, 'abc.abc-abc@abc.commmmm')).toEqual(true);344 expect($.validator.methods['validate-email']345 .call($.validator.prototype, 'abc.abc_abc@abc.commmmm')).toEqual(true);346 expect($.validator.methods['validate-email']347 .call($.validator.prototype, 'abc.abc_abc@abc')).toEqual(false);348 });349 });350 describe('Testing validate-emailSender', function () {351 it('validate-emailSender', function () {352 expect($.validator.methods['validate-emailSender']353 .call($.validator.prototype, '')).toEqual(true);354 expect($.validator.methods['validate-emailSender']355 .call($.validator.prototype, null)).toEqual(true);356 expect($.validator.methods['validate-emailSender']357 .call($.validator.prototype, undefined)).toEqual(true);358 expect($.validator.methods['validate-emailSender']359 .call($.validator.prototype, ' ')).toEqual(true);360 expect($.validator.methods['validate-emailSender']361 .call($.validator.prototype, '123@123.com')).toEqual(true);362 expect($.validator.methods['validate-emailSender']363 .call($.validator.prototype, 'abc@124.en')).toEqual(true);364 expect($.validator.methods['validate-emailSender']365 .call($.validator.prototype, 'abc@abc.commmmm')).toEqual(true);366 expect($.validator.methods['validate-emailSender']367 .call($.validator.prototype, 'abc.abc.abc@abc.commmmm')).toEqual(true);368 expect($.validator.methods['validate-emailSender']369 .call($.validator.prototype, 'abc.abc-abc@abc.commmmm')).toEqual(true);370 expect($.validator.methods['validate-emailSender']371 .call($.validator.prototype, 'abc.abc_abc@abc.commmmm')).toEqual(true);372 });373 });374 describe('Testing validate-password', function () {375 it('validate-password', function () {376 expect($.validator.methods['validate-password']377 .call($.validator.prototype, '')).toEqual(true);378 expect($.validator.methods['validate-password']379 .call($.validator.prototype, null)).toEqual(false);380 expect($.validator.methods['validate-password']381 .call($.validator.prototype, undefined)).toEqual(false);382 expect($.validator.methods['validate-password']383 .call($.validator.prototype, ' ')).toEqual(true);384 expect($.validator.methods['validate-password']385 .call($.validator.prototype, '123@123.com')).toEqual(true);386 expect($.validator.methods['validate-password']387 .call($.validator.prototype, 'abc')).toEqual(false);388 expect($.validator.methods['validate-password']389 .call($.validator.prototype, 'abc ')).toEqual(false);390 expect($.validator.methods['validate-password']391 .call($.validator.prototype, ' abc ')).toEqual(false);392 expect($.validator.methods['validate-password']393 .call($.validator.prototype, 'dddd')).toEqual(false);394 });395 });396 describe('Testing validate-admin-password', function () {397 it('validate-admin-password', function () {398 expect($.validator.methods['validate-admin-password']399 .call($.validator.prototype, '')).toEqual(true);400 expect($.validator.methods['validate-admin-password']401 .call($.validator.prototype, null)).toEqual(false);402 expect($.validator.methods['validate-admin-password']403 .call($.validator.prototype, undefined)).toEqual(false);404 expect($.validator.methods['validate-admin-password']405 .call($.validator.prototype, ' ')).toEqual(true);406 expect($.validator.methods['validate-admin-password']407 .call($.validator.prototype, '123@123.com')).toEqual(true);408 expect($.validator.methods['validate-admin-password']409 .call($.validator.prototype, 'abc')).toEqual(false);410 expect($.validator.methods['validate-admin-password']411 .call($.validator.prototype, 'abc ')).toEqual(false);412 expect($.validator.methods['validate-admin-password']413 .call($.validator.prototype, ' abc ')).toEqual(false);414 expect($.validator.methods['validate-admin-password']415 .call($.validator.prototype, 'dddd')).toEqual(false);416 });417 });418 describe('Testing validate-url', function () {419 it('validate-url', function () {420 expect($.validator.methods['validate-url']421 .call($.validator.prototype, '')).toEqual(true);422 expect($.validator.methods['validate-url']423 .call($.validator.prototype, null)).toEqual(true);424 expect($.validator.methods['validate-url']425 .call($.validator.prototype, undefined)).toEqual(true);426 expect($.validator.methods['validate-url']427 .call($.validator.prototype, ' ')).toEqual(false);428 expect($.validator.methods['validate-url']429 .call($.validator.prototype, 'http://www.google.com')).toEqual(true);430 expect($.validator.methods['validate-url']431 .call($.validator.prototype, 'http://127.0.0.1:8080/index.php')).toEqual(true);432 expect($.validator.methods['validate-url']433 .call($.validator.prototype, 'http://app-spot.com/index.php')).toEqual(true);434 expect($.validator.methods['validate-url']435 .call($.validator.prototype, 'http://app-spot_space.com/index.php')).toEqual(true);436 });437 });438 describe('Testing validate-clean-url', function () {439 it('validate-clean-url', function () {440 expect($.validator.methods['validate-clean-url']441 .call($.validator.prototype, '')).toEqual(true);442 expect($.validator.methods['validate-clean-url']443 .call($.validator.prototype, null)).toEqual(true);444 expect($.validator.methods['validate-clean-url']445 .call($.validator.prototype, undefined)).toEqual(true);446 expect($.validator.methods['validate-clean-url']447 .call($.validator.prototype, ' ')).toEqual(false);448 expect($.validator.methods['validate-clean-url']449 .call($.validator.prototype, 'http://www.google.com')).toEqual(true);450 expect($.validator.methods['validate-clean-url']451 .call($.validator.prototype, 'http://127.0.0.1:8080/index.php')).toEqual(false);452 expect($.validator.methods['validate-clean-url']453 .call($.validator.prototype, 'http://127.0.0.1:8080')).toEqual(false);454 expect($.validator.methods['validate-clean-url']455 .call($.validator.prototype, 'http://127.0.0.1')).toEqual(false);456 });457 });458 describe('Testing validate-xml-identifier', function () {459 it('validate-xml-identifier', function () {460 expect($.validator.methods['validate-xml-identifier']461 .call($.validator.prototype, '')).toEqual(true);462 expect($.validator.methods['validate-xml-identifier']463 .call($.validator.prototype, null)).toEqual(true);464 expect($.validator.methods['validate-xml-identifier']465 .call($.validator.prototype, undefined)).toEqual(true);466 expect($.validator.methods['validate-xml-identifier']467 .call($.validator.prototype, ' ')).toEqual(false);468 expect($.validator.methods['validate-xml-identifier']469 .call($.validator.prototype, 'abc')).toEqual(true);470 expect($.validator.methods['validate-xml-identifier']471 .call($.validator.prototype, 'abc_123')).toEqual(true);472 expect($.validator.methods['validate-xml-identifier']473 .call($.validator.prototype, 'abc-123')).toEqual(true);474 expect($.validator.methods['validate-xml-identifier']475 .call($.validator.prototype, '123-abc')).toEqual(false);476 });477 });478 describe('Testing validate-ssn', function () {479 it('validate-ssn', function () {480 expect($.validator.methods['validate-ssn']481 .call($.validator.prototype, '')).toEqual(true);482 expect($.validator.methods['validate-ssn']483 .call($.validator.prototype, null)).toEqual(true);484 expect($.validator.methods['validate-ssn']485 .call($.validator.prototype, undefined)).toEqual(true);486 expect($.validator.methods['validate-ssn']487 .call($.validator.prototype, ' ')).toEqual(false);488 expect($.validator.methods['validate-ssn']489 .call($.validator.prototype, 'abc')).toEqual(false);490 expect($.validator.methods['validate-ssn']491 .call($.validator.prototype, '123-13-1234')).toEqual(true);492 expect($.validator.methods['validate-ssn']493 .call($.validator.prototype, '012-12-1234')).toEqual(true);494 expect($.validator.methods['validate-ssn']495 .call($.validator.prototype, '23-12-1234')).toEqual(false);496 });497 });498 describe('Testing validate-zip-us', function () {499 it('validate-zip-us', function () {500 expect($.validator.methods['validate-zip-us']501 .call($.validator.prototype, '')).toEqual(true);502 expect($.validator.methods['validate-zip-us']503 .call($.validator.prototype, null)).toEqual(true);504 expect($.validator.methods['validate-zip-us']505 .call($.validator.prototype, undefined)).toEqual(true);506 expect($.validator.methods['validate-zip-us']507 .call($.validator.prototype, ' ')).toEqual(false);508 expect($.validator.methods['validate-zip-us']509 .call($.validator.prototype, '12345-1234')).toEqual(true);510 expect($.validator.methods['validate-zip-us']511 .call($.validator.prototype, '02345')).toEqual(true);512 expect($.validator.methods['validate-zip-us']513 .call($.validator.prototype, '1234')).toEqual(false);514 expect($.validator.methods['validate-zip-us']515 .call($.validator.prototype, '1234-1234')).toEqual(false);516 });517 });518 describe('Testing validate-date-au', function () {519 it('validate-date-au', function () {520 expect($.validator.methods['validate-date-au']521 .call($.validator.prototype, '')).toEqual(true);522 expect($.validator.methods['validate-date-au']523 .call($.validator.prototype, null)).toEqual(true);524 expect($.validator.methods['validate-date-au']525 .call($.validator.prototype, undefined)).toEqual(true);526 expect($.validator.methods['validate-date-au']527 .call($.validator.prototype, ' ')).toEqual(false);528 expect($.validator.methods['validate-date-au']529 .call($.validator.prototype, '01/01/2012')).toEqual(true);530 expect($.validator.methods['validate-date-au']531 .call($.validator.prototype, '30/01/2012')).toEqual(true);532 expect($.validator.methods['validate-date-au']533 .call($.validator.prototype, '01/30/2012')).toEqual(false);534 expect($.validator.methods['validate-date-au']535 .call($.validator.prototype, '1/1/2012')).toEqual(false);536 });537 });538 describe('Testing validate-currency-dollar', function () {539 it('validate-currency-dollar', function () {540 expect($.validator.methods['validate-currency-dollar']541 .call($.validator.prototype, '')).toEqual(true);542 expect($.validator.methods['validate-currency-dollar']543 .call($.validator.prototype, null)).toEqual(true);544 expect($.validator.methods['validate-currency-dollar']545 .call($.validator.prototype, undefined)).toEqual(true);546 expect($.validator.methods['validate-currency-dollar']547 .call($.validator.prototype, ' ')).toEqual(false);548 expect($.validator.methods['validate-currency-dollar']549 .call($.validator.prototype, '$123')).toEqual(true);550 expect($.validator.methods['validate-currency-dollar']551 .call($.validator.prototype, '$1,123.00')).toEqual(true);552 expect($.validator.methods['validate-currency-dollar']553 .call($.validator.prototype, '$1234')).toEqual(true);554 expect($.validator.methods['validate-currency-dollar']555 .call($.validator.prototype, '$1234.1234')).toEqual(false);556 });557 });558 describe('Testing validate-not-negative-number', function () {559 it('validate-not-negative-number', function () {560 expect($.validator.methods['validate-not-negative-number']561 .call($.validator.prototype, '')).toEqual(true);562 expect($.validator.methods['validate-not-negative-number']563 .call($.validator.prototype, null)).toEqual(true);564 expect($.validator.methods['validate-not-negative-number']565 .call($.validator.prototype, undefined)).toEqual(true);566 expect($.validator.methods['validate-not-negative-number']567 .call($.validator.prototype, ' ')).toEqual(false);568 expect($.validator.methods['validate-not-negative-number']569 .call($.validator.prototype, '0')).toEqual(true);570 expect($.validator.methods['validate-not-negative-number']571 .call($.validator.prototype, '1')).toEqual(true);572 expect($.validator.methods['validate-not-negative-number']573 .call($.validator.prototype, '1234')).toEqual(true);574 expect($.validator.methods['validate-not-negative-number']575 .call($.validator.prototype, '1,234.1234')).toEqual(true);576 expect($.validator.methods['validate-not-negative-number']577 .call($.validator.prototype, '-1')).toEqual(false);578 expect($.validator.methods['validate-not-negative-number']579 .call($.validator.prototype, '-1e')).toEqual(false);580 expect($.validator.methods['validate-not-negative-number']581 .call($.validator.prototype, '-1,234.1234')).toEqual(false);582 });583 });584 describe('Testing validate-greater-than-zero', function () {585 it('validate-greater-than-zero', function () {586 expect($.validator.methods['validate-greater-than-zero']587 .call($.validator.prototype, '')).toEqual(true);588 expect($.validator.methods['validate-greater-than-zero']589 .call($.validator.prototype, null)).toEqual(true);590 expect($.validator.methods['validate-greater-than-zero']591 .call($.validator.prototype, undefined)).toEqual(true);592 expect($.validator.methods['validate-greater-than-zero']593 .call($.validator.prototype, ' ')).toEqual(false);594 expect($.validator.methods['validate-greater-than-zero']595 .call($.validator.prototype, '0')).toEqual(false);596 expect($.validator.methods['validate-greater-than-zero']597 .call($.validator.prototype, '1')).toEqual(true);598 expect($.validator.methods['validate-greater-than-zero']599 .call($.validator.prototype, '1234')).toEqual(true);600 expect($.validator.methods['validate-greater-than-zero']601 .call($.validator.prototype, '1,234.1234')).toEqual(true);602 expect($.validator.methods['validate-greater-than-zero']603 .call($.validator.prototype, '-1')).toEqual(false);604 expect($.validator.methods['validate-greater-than-zero']605 .call($.validator.prototype, '-1e')).toEqual(false);606 expect($.validator.methods['validate-greater-than-zero']607 .call($.validator.prototype, '-1,234.1234')).toEqual(false);608 });609 });610 describe('Testing validate-css-length', function () {611 it('validate-css-length', function () {612 expect($.validator.methods['validate-css-length']613 .call($.validator.prototype, '')).toEqual(true);614 expect($.validator.methods['validate-css-length']615 .call($.validator.prototype, null)).toEqual(false);616 expect($.validator.methods['validate-css-length']617 .call($.validator.prototype, undefined)).toEqual(false);618 expect($.validator.methods['validate-css-length']619 .call($.validator.prototype, ' ')).toEqual(false);620 expect($.validator.methods['validate-css-length']621 .call($.validator.prototype, '0')).toEqual(true);622 expect($.validator.methods['validate-css-length']623 .call($.validator.prototype, '1')).toEqual(true);624 expect($.validator.methods['validate-css-length']625 .call($.validator.prototype, '1234')).toEqual(true);626 expect($.validator.methods['validate-css-length']627 .call($.validator.prototype, '1,234.1234')).toEqual(false);628 expect($.validator.methods['validate-css-length']629 .call($.validator.prototype, '-1')).toEqual(false);630 expect($.validator.methods['validate-css-length']631 .call($.validator.prototype, '-1e')).toEqual(false);632 expect($.validator.methods['validate-css-length']633 .call($.validator.prototype, '-1,234.1234')).toEqual(false);634 });635 });636 describe('Testing validate-data', function () {637 it('validate-data', function () {638 expect($.validator.methods['validate-data']639 .call($.validator.prototype, '')).toEqual(true);640 expect($.validator.methods['validate-data']641 .call($.validator.prototype, null)).toEqual(true);642 expect($.validator.methods['validate-data']643 .call($.validator.prototype, undefined)).toEqual(true);644 expect($.validator.methods['validate-data']645 .call($.validator.prototype, ' ')).toEqual(false);646 expect($.validator.methods['validate-data']647 .call($.validator.prototype, '123abc')).toEqual(false);648 expect($.validator.methods['validate-data']649 .call($.validator.prototype, 'abc')).toEqual(true);650 expect($.validator.methods['validate-data']651 .call($.validator.prototype, ' abc')).toEqual(false);652 expect($.validator.methods['validate-data']653 .call($.validator.prototype, 'abc123')).toEqual(true);654 expect($.validator.methods['validate-data']655 .call($.validator.prototype, 'abc-123')).toEqual(false);656 });657 });658 describe('Testing validate-one-required-by-name', function () {659 it('validate-one-required-by-name', function () {660 var radio = $('<input type="radio" name="radio"/>'),661 radio2 = $('<input type="radio" name="radio" checked/>'),662 checkbox = $('<input type="checkbox" name="checkbox"/>'),663 checkbox2 = $('<input type="checkbox" name="checkbox" checked/>'),664 $test = $('<div id="test-block" />'),665 prevForm = $.validator.prototype.currentForm;666 $.validator.prototype.currentForm = $test[0];667 $test.append(radio);668 expect($.validator.methods['validate-one-required-by-name']669 .call($.validator.prototype, null, radio[0], true)).toEqual(false);670 $test.append(radio2);671 expect($.validator.methods['validate-one-required-by-name']672 .call($.validator.prototype, null, radio2[0], true)).toEqual(true);673 $test.append(checkbox);674 expect($.validator.methods['validate-one-required-by-name']675 .call($.validator.prototype, null, checkbox[0], true)).toEqual(false);676 $test.append(checkbox2);677 expect($.validator.methods['validate-one-required-by-name']678 .call($.validator.prototype, null, checkbox2[0], true)).toEqual(true);679 $.validator.prototype.currentForm = prevForm;680 });681 });682 describe('Testing less-than-equals-to', function () {683 it('less-than-equals-to', function () {684 var elm1 = $('<input type="text" value="6" id="element1" />'),685 elm2 = $('<input type="text" value="5" id="element2" />'),686 elm3 = $('<input type="text" id="element3" />'),687 elm4 = $('<input type="text" value=5 id="element4" />'),688 elm5 = $('<input type="text" id="element6" />'),689 elm6 = $('<input type="text" value=6 id="element5" />'),690 elm7 = $('<input type="text" value=20 id="element7" />'),691 elm8 = $('<input type="text" value=100 id="element8" />');692 expect($.validator.methods['less-than-equals-to']693 .call($.validator.prototype, elm1[0].value, elm1, elm2)).toEqual(false);694 elm1[0].value = 4;695 expect($.validator.methods['less-than-equals-to']696 .call($.validator.prototype, elm1[0].value, elm1, elm2)).toEqual(true);697 expect($.validator.methods['less-than-equals-to']698 .call($.validator.prototype, elm3[0].value, elm3, elm4)).toEqual(true);699 expect($.validator.methods['less-than-equals-to']700 .call($.validator.prototype, elm5[0].value, elm5, elm6)).toEqual(true);701 expect($.validator.methods['less-than-equals-to']702 .call($.validator.prototype, elm7[0].value, elm7, elm8)).toEqual(true);703 });704 });705 describe('Testing greater-than-equals-to', function () {706 it('greater-than-equals-to', function () {707 var elm1 = $('<input type="text" value=6 id="element1" />'),708 elm2 = $('<input type="text" value=7 id="element2" />'),709 elm3 = $('<input type="text" id="element3" />'),710 elm4 = $('<input type="text" value=5 id="element4" />'),711 elm5 = $('<input type="text" id="element6" />'),712 elm6 = $('<input type="text" value=6 id="element5" />'),713 elm7 = $('<input type="text" value=100 id="element7" />'),714 elm8 = $('<input type="text" value=20 id="element8" />');715 expect($.validator.methods['greater-than-equals-to']716 .call($.validator.prototype, elm1[0].value, elm1, elm2)).toEqual(false);717 elm1[0].value = 9;718 expect($.validator.methods['greater-than-equals-to']719 .call($.validator.prototype, elm1[0].value, elm1, elm2)).toEqual(true);720 expect($.validator.methods['greater-than-equals-to']721 .call($.validator.prototype, elm3[0].value, elm3, elm4)).toEqual(true);722 expect($.validator.methods['greater-than-equals-to']723 .call($.validator.prototype, elm5[0].value, elm5, elm6)).toEqual(true);724 expect($.validator.methods['greater-than-equals-to']725 .call($.validator.prototype, elm7[0].value, elm7, elm8)).toEqual(true);726 });727 });728 describe('Testing validate-cc-type-select', function () {729 it('validate-cc-type-select', function () {730 var visaValid = $('<input id="visa-valid" type="text" value="4916808263499650"/>'),731 visaInvalid = $('<input id="visa-invalid" type="text" value="1234567890123456"/>'),732 mcValid = $('<input id="mc-valid" type="text" value="5203731841177490"/>'),733 mcInvalid = $('<input id="mc-invalid" type="text" value="1111222233334444"/>'),734 aeValid = $('<input id="ae-valid" type="text" value="376244899619217"/>'),735 aeInvalid = $('<input id="ae-invalid" type="text" value="123451234512345"/>'),736 diValid = $('<input id="di-valid" type="text" value="6011050000000009"/>'),737 diInvalid = $('<input id="di-invalid" type="text" value="6011199900000005"/>'),738 dnValid = $('<input id="dn-valid" type="text" value="3095434000000001"/>'),739 dnInvalid = $('<input id="dn-invalid" type="text" value="3799999900000003"/>'),740 jcbValid = $('<input id="jcb-valid" type="text" value="3528000000000007"/>'),741 jcbInvalid = $('<input id="jcb-invalid" type="text" value="359000001111118"/>');742 expect($.validator.methods['validate-cc-type-select']743 .call($.validator.prototype, 'VI', null, visaValid)).toEqual(true);744 expect($.validator.methods['validate-cc-type-select']745 .call($.validator.prototype, 'VI', null, visaInvalid)).toEqual(false);746 expect($.validator.methods['validate-cc-type-select']747 .call($.validator.prototype, 'MC', null, mcValid)).toEqual(true);748 expect($.validator.methods['validate-cc-type-select']749 .call($.validator.prototype, 'MC', null, mcInvalid)).toEqual(false);750 expect($.validator.methods['validate-cc-type-select']751 .call($.validator.prototype, 'AE', null, aeValid)).toEqual(true);752 expect($.validator.methods['validate-cc-type-select']753 .call($.validator.prototype, 'AE', null, aeInvalid)).toEqual(false);754 expect($.validator.methods['validate-cc-type-select']755 .call($.validator.prototype, 'DI', null, diValid)).toEqual(true);756 expect($.validator.methods['validate-cc-type-select']757 .call($.validator.prototype, 'DI', null, diInvalid)).toEqual(false);758 expect($.validator.methods['validate-cc-type-select']759 .call($.validator.prototype, 'DN', null, dnValid)).toEqual(true);760 expect($.validator.methods['validate-cc-type-select']761 .call($.validator.prototype, 'DN', null, dnInvalid)).toEqual(false);762 expect($.validator.methods['validate-cc-type-select']763 .call($.validator.prototype, 'JCB', null, jcbValid)).toEqual(true);764 expect($.validator.methods['validate-cc-type-select']765 .call($.validator.prototype, 'JCB', null, jcbInvalid)).toEqual(false);766 });767 });768 describe('Testing validate-cc-number', function () {769 it('validate-cc-number', function () {770 expect($.validator.methods['validate-cc-number']771 .call($.validator.prototype, '4916835098995909', null, null)).toEqual(true);772 expect($.validator.methods['validate-cc-number']773 .call($.validator.prototype, '5265071363284878', null, null)).toEqual(true);774 expect($.validator.methods['validate-cc-number']775 .call($.validator.prototype, '6011120623356953', null, null)).toEqual(true);776 expect($.validator.methods['validate-cc-number']777 .call($.validator.prototype, '371293266574617', null, null)).toEqual(true);778 expect($.validator.methods['validate-cc-number']779 .call($.validator.prototype, '4916835098995901', null, null)).toEqual(false);780 expect($.validator.methods['validate-cc-number']781 .call($.validator.prototype, '5265071363284870', null, null)).toEqual(false);782 expect($.validator.methods['validate-cc-number']783 .call($.validator.prototype, '6011120623356951', null, null)).toEqual(false);784 expect($.validator.methods['validate-cc-number']785 .call($.validator.prototype, '371293266574619', null, null)).toEqual(false);786 expect($.validator.methods['validate-cc-number']787 .call($.validator.prototype, '2221220000000003', null, null)).toEqual(true);788 expect($.validator.methods['validate-cc-number']789 .call($.validator.prototype, '2721220000000008', null, null)).toEqual(true);790 expect($.validator.methods['validate-cc-number']791 .call($.validator.prototype, '601109020000000003', null, null)).toEqual(true);792 expect($.validator.methods['validate-cc-number']793 .call($.validator.prototype, '6011111144444444', null, null)).toEqual(true);794 expect($.validator.methods['validate-cc-number']795 .call($.validator.prototype, '6011222233334444', null, null)).toEqual(true);796 expect($.validator.methods['validate-cc-number']797 .call($.validator.prototype, '6011522233334447', null, null)).toEqual(true);798 expect($.validator.methods['validate-cc-number']799 .call($.validator.prototype, '601174455555553', null, null)).toEqual(true);800 expect($.validator.methods['validate-cc-number']801 .call($.validator.prototype, '6011745555555550', null, null)).toEqual(true);802 expect($.validator.methods['validate-cc-number']803 .call($.validator.prototype, '601177455555556', null, null)).toEqual(true);804 expect($.validator.methods['validate-cc-number']805 .call($.validator.prototype, '601182455555556', null, null)).toEqual(true);806 expect($.validator.methods['validate-cc-number']807 .call($.validator.prototype, '601187999555558', null, null)).toEqual(true);808 expect($.validator.methods['validate-cc-number']809 .call($.validator.prototype, '601287999555556', null, null)).toEqual(true);810 expect($.validator.methods['validate-cc-number']811 .call($.validator.prototype, '6444444444444443', null, null)).toEqual(true);812 expect($.validator.methods['validate-cc-number']813 .call($.validator.prototype, '6644444444444441', null, null)).toEqual(true);814 expect($.validator.methods['validate-cc-number']815 .call($.validator.prototype, '3044444444444444', null, null)).toEqual(true);816 expect($.validator.methods['validate-cc-number']817 .call($.validator.prototype, '3064444444444449', null, null)).toEqual(true);818 expect($.validator.methods['validate-cc-number']819 .call($.validator.prototype, '3095444444444442', null, null)).toEqual(true);820 expect($.validator.methods['validate-cc-number']821 .call($.validator.prototype, '3096444444444441', null, null)).toEqual(true);822 expect($.validator.methods['validate-cc-number']823 .call($.validator.prototype, '3696444444444445', null, null)).toEqual(true);824 expect($.validator.methods['validate-cc-number']825 .call($.validator.prototype, '3796444444444444', null, null)).toEqual(true);826 expect($.validator.methods['validate-cc-number']827 .call($.validator.prototype, '3896444444444443', null, null)).toEqual(true);828 expect($.validator.methods['validate-cc-number']829 .call($.validator.prototype, '3528444444444449', null, null)).toEqual(true);830 expect($.validator.methods['validate-cc-number']831 .call($.validator.prototype, '3529444444444448', null, null)).toEqual(true);832 expect($.validator.methods['validate-cc-number']833 .call($.validator.prototype, '6221262244444440', null, null)).toEqual(true);834 expect($.validator.methods['validate-cc-number']835 .call($.validator.prototype, '6229981111111111', null, null)).toEqual(true);836 expect($.validator.methods['validate-cc-number']837 .call($.validator.prototype, '6249981111111117', null, null)).toEqual(true);838 expect($.validator.methods['validate-cc-number']839 .call($.validator.prototype, '6279981111111110', null, null)).toEqual(true);840 expect($.validator.methods['validate-cc-number']841 .call($.validator.prototype, '6282981111111115', null, null)).toEqual(true);842 expect($.validator.methods['validate-cc-number']843 .call($.validator.prototype, '6289981111111118', null, null)).toEqual(true);844 });845 });846 describe('Testing validate-cc-type', function () {847 it('validate-cc-type', function () {848 var select = $('<select id="cc-type">' +849 '<option value="">' +850 '</option><option value="VI">' +851 '</option><option value="MC">' +852 '</option><option value="AE">' +853 '</option><option value="DI">' +854 '</option><option value="DN">' +855 '</option><option value="JCB">' +856 '</option><option value="UP">' +857 '</option>' +858 '</select>');859 select.val('VI');860 expect($.validator.methods['validate-cc-type']861 .call($.validator.prototype, '4916835098995909', null, select)).toEqual(true);862 expect($.validator.methods['validate-cc-type']863 .call($.validator.prototype, '5265071363284878', null, select)).toEqual(false);864 select.val('MC');865 expect($.validator.methods['validate-cc-type']866 .call($.validator.prototype, '5265071363284878', null, select)).toEqual(true);867 expect($.validator.methods['validate-cc-type']868 .call($.validator.prototype, '4916835098995909', null, select)).toEqual(false);869 select.val('AE');870 expect($.validator.methods['validate-cc-type']871 .call($.validator.prototype, '371293266574617', null, select)).toEqual(true);872 expect($.validator.methods['validate-cc-type']873 .call($.validator.prototype, '5265071363284878', null, select)).toEqual(false);874 select.val('DI');875 expect($.validator.methods['validate-cc-type']876 .call($.validator.prototype, '6011050000000009', null, select)).toEqual(true);877 expect($.validator.methods['validate-cc-type']878 .call($.validator.prototype, '371293266574617', null, select)).toEqual(false);879 select.val('DN');880 expect($.validator.methods['validate-cc-type']881 .call($.validator.prototype, '3095434000000001', null, select)).toEqual(true);882 expect($.validator.methods['validate-cc-type']883 .call($.validator.prototype, '6011050000000009', null, select)).toEqual(false);884 select.val('JCB');885 expect($.validator.methods['validate-cc-type']886 .call($.validator.prototype, '3528000000000007', null, select)).toEqual(true);887 expect($.validator.methods['validate-cc-type']888 .call($.validator.prototype, '3095434000000001', null, select)).toEqual(false);889 });890 });891 describe('Testing validate-cc-exp', function () {892 it('validate-cc-exp', function () {893 var year = $('<input id="year" type="text" value="4916808263499650"/>'),894 currentTime = new Date(),895 currentMonth = currentTime.getMonth() + 1,896 currentYear = currentTime.getFullYear();897 year.val(currentYear);898 if (currentMonth > 1) {899 expect($.validator.methods['validate-cc-exp']900 .call($.validator.prototype, currentMonth - 1, null, year)).toEqual(false);901 }902 expect($.validator.methods['validate-cc-exp']903 .call($.validator.prototype, currentMonth, null, year)).toEqual(true);904 year.val(currentYear + 1);905 expect($.validator.methods['validate-cc-exp']906 .call($.validator.prototype, currentMonth, null, year)).toEqual(true);907 });908 });909 describe('Testing validate-cc-cvn', function () {910 it('validate-cc-cvn', function () {911 var ccType = $('<select id="cc-type">' +912 '<option value=""></option>' +913 '<option value="VI"></option>' +914 '<option value="MC"></option>' +915 '<option value="AE"></option>' +916 '<option value="DI"></option>' +917 '</select>');918 ccType.val('VI');919 expect($.validator.methods['validate-cc-cvn']920 .call($.validator.prototype, '123', null, ccType)).toEqual(true);921 expect($.validator.methods['validate-cc-cvn']922 .call($.validator.prototype, '1234', null, ccType)).toEqual(false);923 ccType.val('MC');924 expect($.validator.methods['validate-cc-cvn']925 .call($.validator.prototype, '123', null, ccType)).toEqual(true);926 expect($.validator.methods['validate-cc-cvn']927 .call($.validator.prototype, '1234', null, ccType)).toEqual(false);928 ccType.val('AE');929 expect($.validator.methods['validate-cc-cvn']930 .call($.validator.prototype, '1234', null, ccType)).toEqual(true);931 expect($.validator.methods['validate-cc-cvn']932 .call($.validator.prototype, '123', null, ccType)).toEqual(false);933 ccType.val('DI');934 expect($.validator.methods['validate-cc-cvn']935 .call($.validator.prototype, '123', null, ccType)).toEqual(true);936 expect($.validator.methods['validate-cc-cvn']937 .call($.validator.prototype, '1234', null, ccType)).toEqual(false);938 });939 });940 describe('Testing validate-number-range', function () {941 it('validate-number-range', function () {942 var el1 = $('<input type="text" value="" ' +943 'class="validate-number-range number-range-10-20 number-range-10-100.20">').get(0);944 expect($.validator.methods['validate-number-range']945 .call($.validator.prototype, '-1', null, null)).toEqual(true);946 expect($.validator.methods['validate-number-range']947 .call($.validator.prototype, '1', null, null)).toEqual(true);948 expect($.validator.methods['validate-number-range']949 .call($.validator.prototype, '', null, null)).toEqual(true);950 expect($.validator.methods['validate-number-range']951 .call($.validator.prototype, null, null, null)).toEqual(true);952 expect($.validator.methods['validate-number-range']953 .call($.validator.prototype, '0', null, null)).toEqual(true);954 expect($.validator.methods['validate-number-range']955 .call($.validator.prototype, 'asds', null, null)).toEqual(false);956 expect($.validator.methods['validate-number-range']957 .call($.validator.prototype, '10', null, '10-20.06')).toEqual(true);958 expect($.validator.methods['validate-number-range']959 .call($.validator.prototype, '15', null, '10-20.06')).toEqual(true);960 expect($.validator.methods['validate-number-range']961 .call($.validator.prototype, '1', null, '10-20.06')).toEqual(false);962 expect($.validator.methods['validate-number-range']963 .call($.validator.prototype, '30', null, '10-20.06')).toEqual(false);964 expect($.validator.methods['validate-number-range']965 .call($.validator.prototype, '10', el1, null)).toEqual(true);966 expect($.validator.methods['validate-number-range']967 .call($.validator.prototype, '15', el1, null)).toEqual(true);968 expect($.validator.methods['validate-number-range']969 .call($.validator.prototype, '1', el1, null)).toEqual(false);970 expect($.validator.methods['validate-number-range']971 .call($.validator.prototype, '30', el1, null)).toEqual(true);972 });973 });974 describe('Testing validate-digits-range', function () {975 it('validate-digits-range', function () {976 var el1 = $('<input type="text" value="" ' +977 'class="validate-digits-range digits-range-10-20 digits-range-10-100.20">').get(0);978 expect($.validator.methods['validate-digits-range']979 .call($.validator.prototype, '-1', null, null)).toEqual(true);980 expect($.validator.methods['validate-digits-range']981 .call($.validator.prototype, '1', null, null)).toEqual(true);982 expect($.validator.methods['validate-digits-range']983 .call($.validator.prototype, '', null, null)).toEqual(true);984 expect($.validator.methods['validate-digits-range']985 .call($.validator.prototype, null, null, null)).toEqual(true);986 expect($.validator.methods['validate-digits-range']987 .call($.validator.prototype, '0', null, null)).toEqual(true);988 expect($.validator.methods['validate-digits-range']989 .call($.validator.prototype, 'asds', null, null)).toEqual(false);990 expect($.validator.methods['validate-digits-range']991 .call($.validator.prototype, '10', null, '10-20')).toEqual(true);992 expect($.validator.methods['validate-digits-range']993 .call($.validator.prototype, '15', null, '10-20')).toEqual(true);994 expect($.validator.methods['validate-digits-range']995 .call($.validator.prototype, '1', null, '10-20')).toEqual(false);996 expect($.validator.methods['validate-digits-range']997 .call($.validator.prototype, '30', null, '10-20')).toEqual(false);998 expect($.validator.methods['validate-digits-range']999 .call($.validator.prototype, '30', null, '10-20.06')).toEqual(false);1000 expect($.validator.methods['validate-digits-range']1001 .call($.validator.prototype, '10', el1, null)).toEqual(true);1002 expect($.validator.methods['validate-digits-range']1003 .call($.validator.prototype, '15', el1, null)).toEqual(true);1004 expect($.validator.methods['validate-digits-range']1005 .call($.validator.prototype, '1', el1, null)).toEqual(false);1006 expect($.validator.methods['validate-digits-range']1007 .call($.validator.prototype, '30', el1, null)).toEqual(false);1008 });1009 });1010 describe('Testing 3 bytes characters only policy (UTF-8)', function () {1011 it('rejects data, if any of the characters cannot be stored using UTF-8 collation', function () {1012 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1013 $.validator.prototype, '😅😂', null1014 )).toEqual(false);1015 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1016 $.validator.prototype, '😅 test 😂', null1017 )).toEqual(false);1018 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1019 $.validator.prototype, '💩 👻 💀', null1020 )).toEqual(false);1021 });1022 it('approves data, if all the characters can be stored using UTF-8 collation', function () {1023 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1024 $.validator.prototype, '', null1025 )).toEqual(true);1026 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1027 $.validator.prototype, '!$-_%ç&#?!', null1028 )).toEqual(true);1029 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1030 $.validator.prototype, '1234567890', null1031 )).toEqual(true);1032 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1033 $.validator.prototype, ' ', null1034 )).toEqual(true);1035 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1036 $.validator.prototype, 'test', null1037 )).toEqual(true);1038 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1039 $.validator.prototype, 'испытание', null1040 )).toEqual(true);1041 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1042 $.validator.prototype, 'тест', null1043 )).toEqual(true);1044 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1045 $.validator.prototype, 'փորձարկում', null1046 )).toEqual(true);1047 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1048 $.validator.prototype, 'परीक्षण', null1049 )).toEqual(true);1050 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1051 $.validator.prototype, 'テスト', null1052 )).toEqual(true);1053 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1054 $.validator.prototype, '테스트', null1055 )).toEqual(true);1056 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1057 $.validator.prototype, '测试', null1058 )).toEqual(true);1059 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1060 $.validator.prototype, '測試', null1061 )).toEqual(true);1062 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1063 $.validator.prototype, 'ทดสอบ', null1064 )).toEqual(true);1065 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1066 $.validator.prototype, 'δοκιμή', null1067 )).toEqual(true);1068 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1069 $.validator.prototype, 'اختبار', null1070 )).toEqual(true);1071 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1072 $.validator.prototype, 'تست', null1073 )).toEqual(true);1074 expect($.validator.methods['validate-no-utf8mb4-characters'].call(1075 $.validator.prototype, 'מִבְחָן', null1076 )).toEqual(true);1077 });1078 });1079 describe('Testing validate-forbidden-extensions', function () {1080 it('validate-forbidden-extensions', function () {1081 var el1 = $('<input type="text" value="" ' +1082 'class="validate-extensions" data-validation-params="php,phtml">').get(0);1083 expect($.validator.methods['validate-forbidden-extensions']1084 .call($.validator.prototype, 'php', el1, null)).toEqual(false);1085 expect($.validator.methods['validate-forbidden-extensions']1086 .call($.validator.prototype, 'php,phtml', el1, null)).toEqual(false);1087 expect($.validator.methods['validate-forbidden-extensions']1088 .call($.validator.prototype, 'html', el1, null)).toEqual(true);1089 expect($.validator.methods['validate-forbidden-extensions']1090 .call($.validator.prototype, 'html,png', el1, null)).toEqual(true);1091 expect($.validator.methods['validate-forbidden-extensions']1092 .call($.validator.prototype, 'php,html', el1, null)).toEqual(false);1093 expect($.validator.methods['validate-forbidden-extensions']1094 .call($.validator.prototype, 'html,php', el1, null)).toEqual(false);1095 });1096 });...

Full Screen

Full Screen

test-validation.js

Source:test-validation.js Github

copy

Full Screen

1/**2 * Copyright © 2016 Magento. All rights reserved.3 * See COPYING.txt for license details.4 */5test( "testValidateNoHtmlTags", function() {6 expect(4);7 equal($.validator.methods['validate-no-html-tags'].call(this, ""),true);8 equal($.validator.methods['validate-no-html-tags'].call(this, null),true);9 equal($.validator.methods['validate-no-html-tags'].call(this, "abc"),true);10 equal($.validator.methods['validate-no-html-tags'].call(this, "<div>abc</div>"),false);11});12test( "testAllowContainerClassName", function() {13 expect(4);14 var radio = $('<input type="radio" class="change-container-classname"/>');15 radio.appendTo("#qunit-fixture");16 equal($.validator.methods['allow-container-className'].call(this, radio[0]),true);17 var checkbox = $('<input type="checkbox" class="change-container-classname"/>');18 equal($.validator.methods['allow-container-className'].call(this, checkbox[0]),true);19 var radio2 = $('<input type="radio"/>');20 equal($.validator.methods['allow-container-className'].call(this, radio2[0]),false);21 var checkbox2 = $('<input type="checkbox"/>');22 equal($.validator.methods['allow-container-className'].call(this, checkbox2[0]),false);23});24test( "testValidateSelect", function() {25 expect(5);26 equal($.validator.methods['validate-select'].call(this, ""),false);27 equal($.validator.methods['validate-select'].call(this, "none"),false);28 equal($.validator.methods['validate-select'].call(this, null),false);29 equal($.validator.methods['validate-select'].call(this, undefined),false);30 equal($.validator.methods['validate-select'].call(this, "abc"),true);31});32test( "testValidateNotEmpty", function() {33 expect(5);34 ok(!$.validator.methods['validate-no-empty'].call(this, ""));35 ok(!$.validator.methods['validate-no-empty'].call(this, null));36 ok(!$.validator.methods['validate-no-empty'].call(this, undefined));37 ok(!$.validator.methods['validate-no-empty'].call(this, " "));38 ok($.validator.methods['validate-no-empty'].call(this, "test"));39});40test( "testValidateStreet", function() {41 expect(9);42 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, ""),true);43 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, null),true);44 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, undefined),true);45 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, " "),true);46 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, "abc "),true);47 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, " 123 "),true);48 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, " abc123 "),true);49 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, " !@# "),false);50 equal($.validator.methods['validate-alphanum-with-spaces'].call(this, " abc.123 "),false);51});52test( "testValidatePhoneStrict", function() {53 expect(9);54 equal($.validator.methods['validate-phoneStrict'].call(this, ""),true);55 equal($.validator.methods['validate-phoneStrict'].call(this, null),true);56 equal($.validator.methods['validate-phoneStrict'].call(this, undefined),true);57 equal($.validator.methods['validate-phoneStrict'].call(this, " "),false);58 equal($.validator.methods['validate-phoneStrict'].call(this, "5121231234"),false);59 equal($.validator.methods['validate-phoneStrict'].call(this, "512.123.1234"),false);60 equal($.validator.methods['validate-phoneStrict'].call(this, "512-123-1234"),true);61 equal($.validator.methods['validate-phoneStrict'].call(this, "(512)123-1234"),true);62 equal($.validator.methods['validate-phoneStrict'].call(this, "(512) 123-1234"),true);63});64test( "testValidatePhoneLax", function() {65 expect(11);66 equal($.validator.methods['validate-phoneLax'].call(this, ""),true);67 equal($.validator.methods['validate-phoneLax'].call(this, null),true);68 equal($.validator.methods['validate-phoneLax'].call(this, undefined),true);69 equal($.validator.methods['validate-phoneLax'].call(this, " "),false);70 equal($.validator.methods['validate-phoneLax'].call(this, "5121231234"),true);71 equal($.validator.methods['validate-phoneLax'].call(this, "512.123.1234"),true);72 equal($.validator.methods['validate-phoneLax'].call(this, "512-123-1234"),true);73 equal($.validator.methods['validate-phoneLax'].call(this, "(512)123-1234"),true);74 equal($.validator.methods['validate-phoneLax'].call(this, "(512) 123-1234"),true);75 equal($.validator.methods['validate-phoneLax'].call(this, "(512)1231234"),true);76 equal($.validator.methods['validate-phoneLax'].call(this, "(512)_123_1234"),false);77});78test( "testValidateFax", function() {79 expect(9);80 equal($.validator.methods['validate-fax'].call(this, ""),true);81 equal($.validator.methods['validate-fax'].call(this, null),true);82 equal($.validator.methods['validate-fax'].call(this, undefined),true);83 equal($.validator.methods['validate-fax'].call(this, " "),false);84 equal($.validator.methods['validate-fax'].call(this, "5121231234"),false);85 equal($.validator.methods['validate-fax'].call(this, "512.123.1234"),false);86 equal($.validator.methods['validate-fax'].call(this, "512-123-1234"),true);87 equal($.validator.methods['validate-fax'].call(this, "(512)123-1234"),true);88 equal($.validator.methods['validate-fax'].call(this, "(512) 123-1234"),true);89});90test( "testValidateEmail", function() {91 expect(11);92 equal($.validator.methods['validate-email'].call(this, ""),true);93 equal($.validator.methods['validate-email'].call(this, null),true);94 equal($.validator.methods['validate-email'].call(this, undefined),true);95 equal($.validator.methods['validate-email'].call(this, " "),false);96 equal($.validator.methods['validate-email'].call(this, "123@123.com"),true);97 equal($.validator.methods['validate-email'].call(this, "abc@124.en"),true);98 equal($.validator.methods['validate-email'].call(this, "abc@abc.commmmm"),true);99 equal($.validator.methods['validate-email'].call(this, "abc.abc.abc@abc.commmmm"),true);100 equal($.validator.methods['validate-email'].call(this, "abc.abc-abc@abc.commmmm"),true);101 equal($.validator.methods['validate-email'].call(this, "abc.abc_abc@abc.commmmm"),true);102 equal($.validator.methods['validate-email'].call(this, "abc.abc_abc@abc"),false);103});104test( "testValidateEmailSender", function() {105 expect(10);106 equal($.validator.methods['validate-emailSender'].call(this, ""),true);107 equal($.validator.methods['validate-emailSender'].call(null),true);108 equal($.validator.methods['validate-emailSender'].call(undefined),true);109 equal($.validator.methods['validate-emailSender'].call(" "),true);110 equal($.validator.methods['validate-emailSender'].call("123@123.com"),true);111 equal($.validator.methods['validate-emailSender'].call("abc@124.en"),true);112 equal($.validator.methods['validate-emailSender'].call("abc@abc.commmmm"),true);113 equal($.validator.methods['validate-emailSender'].call("abc.abc.abc@abc.commmmm"),true);114 equal($.validator.methods['validate-emailSender'].call("abc.abc-abc@abc.commmmm"),true);115 equal($.validator.methods['validate-emailSender'].call("abc.abc_abc@abc.commmmm"),true);116});117test( "testValidatePassword", function() {118 expect(9);119 equal($.validator.methods['validate-password'].call(this, ""),true);120 equal($.validator.methods['validate-password'].call(this, null),false);121 equal($.validator.methods['validate-password'].call(this, undefined),false);122 equal($.validator.methods['validate-password'].call(this, " "),true);123 equal($.validator.methods['validate-password'].call(this, "123@123.com"),true);124 equal($.validator.methods['validate-password'].call(this, "abc"),false);125 equal($.validator.methods['validate-password'].call(this, "abc "),false);126 equal($.validator.methods['validate-password'].call(this, " abc "),false);127 equal($.validator.methods['validate-password'].call(this, "dddd"),false);128});129test( "testValidateAdminPassword", function() {130 expect(9);131 equal(true, $.validator.methods['validate-admin-password'].call(this, ""));132 equal(false, $.validator.methods['validate-admin-password'].call(this, null));133 equal(false, $.validator.methods['validate-admin-password'].call(this, undefined));134 equal(true, $.validator.methods['validate-admin-password'].call(this, " "));135 equal(true, $.validator.methods['validate-admin-password'].call(this, "123@123.com"));136 equal(false, $.validator.methods['validate-admin-password'].call(this, "abc"));137 equal(false, $.validator.methods['validate-admin-password'].call(this, "abc "));138 equal(false, $.validator.methods['validate-admin-password'].call(this, " abc "));139 equal(false, $.validator.methods['validate-admin-password'].call(this, "dddd"));140});141test( "testValidateUrl", function() {142 expect(8);143 equal(true, $.validator.methods['validate-url'].call(this, ""));144 equal(true, $.validator.methods['validate-url'].call(this, null));145 equal(true, $.validator.methods['validate-url'].call(this, undefined));146 equal(false, $.validator.methods['validate-url'].call(this, " "));147 equal(true, $.validator.methods['validate-url'].call(this, "http://www.google.com"));148 equal(true, $.validator.methods['validate-url'].call(this, "http://127.0.0.1:8080/index.php"));149 equal(true, $.validator.methods['validate-url'].call(this, "http://app-spot.com/index.php"));150 equal(true, $.validator.methods['validate-url'].call(this, "http://app-spot_space.com/index.php"));151});152test( "testValidateCleanUrl", function() {153 expect(8);154 equal(true, $.validator.methods['validate-clean-url'].call(this, ""));155 equal(true, $.validator.methods['validate-clean-url'].call(this, null));156 equal(true, $.validator.methods['validate-clean-url'].call(this, undefined));157 equal(false, $.validator.methods['validate-clean-url'].call(this, " "));158 equal(true, $.validator.methods['validate-clean-url'].call(this, "http://www.google.com"));159 equal(false, $.validator.methods['validate-clean-url'].call(this, "http://127.0.0.1:8080/index.php"));160 equal(false, $.validator.methods['validate-clean-url'].call(this, "http://127.0.0.1:8080"));161 equal(false, $.validator.methods['validate-clean-url'].call(this, "http://127.0.0.1"));162});163test( "testValidateXmlIdentifier", function() {164 expect(8);165 equal(true, $.validator.methods['validate-xml-identifier'].call(this, ""));166 equal(true, $.validator.methods['validate-xml-identifier'].call(this, null));167 equal(true, $.validator.methods['validate-xml-identifier'].call(this, undefined));168 equal(false, $.validator.methods['validate-xml-identifier'].call(this, " "));169 equal(true, $.validator.methods['validate-xml-identifier'].call(this, "abc"));170 equal(true, $.validator.methods['validate-xml-identifier'].call(this, "abc_123"));171 equal(true, $.validator.methods['validate-xml-identifier'].call(this, "abc-123"));172 equal(false, $.validator.methods['validate-xml-identifier'].call(this, "123-abc"));173});174test( "testValidateSsn", function() {175 expect(8);176 equal(true, $.validator.methods['validate-ssn'].call(this, ""));177 equal(true, $.validator.methods['validate-ssn'].call(this, null));178 equal(true, $.validator.methods['validate-ssn'].call(this, undefined));179 equal(false, $.validator.methods['validate-ssn'].call(this, " "));180 equal(false, $.validator.methods['validate-ssn'].call(this, "abc"));181 equal(true, $.validator.methods['validate-ssn'].call(this, "123-13-1234"));182 equal(true, $.validator.methods['validate-ssn'].call(this, "012-12-1234"));183 equal(false, $.validator.methods['validate-ssn'].call(this, "23-12-1234"));184});185test( "testValidateZip", function() {186 expect(8);187 equal(true, $.validator.methods['validate-zip-us'].call(this, ""));188 equal(true, $.validator.methods['validate-zip-us'].call(this, null));189 equal(true, $.validator.methods['validate-zip-us'].call(this, undefined));190 equal(false, $.validator.methods['validate-zip-us'].call(this, " "));191 equal(true, $.validator.methods['validate-zip-us'].call(this, "12345-1234"));192 equal(true, $.validator.methods['validate-zip-us'].call(this, "02345"));193 equal(false, $.validator.methods['validate-zip-us'].call(this, "1234"));194 equal(false, $.validator.methods['validate-zip-us'].call(this, "1234-1234"));195});196test( "testValidateDateAu", function() {197 expect(8);198 equal(true, $.validator.methods['validate-date-au'].call(this, ""));199 equal(true, $.validator.methods['validate-date-au'].call(this, null));200 equal(true, $.validator.methods['validate-date-au'].call(this, undefined));201 equal(false, $.validator.methods['validate-date-au'].call(this, " "));202 equal(true, $.validator.methods['validate-date-au'].call(this, "01/01/2012"));203 equal(true, $.validator.methods['validate-date-au'].call(this, "30/01/2012"));204 equal(false, $.validator.methods['validate-date-au'].call(this, "01/30/2012"));205 equal(false, $.validator.methods['validate-date-au'].call(this, "1/1/2012"));206});207test( "testValidateCurrencyDollar", function() {208 expect(8);209 equal(true, $.validator.methods['validate-currency-dollar'].call(this, ""));210 equal(true, $.validator.methods['validate-currency-dollar'].call(this, null));211 equal(true, $.validator.methods['validate-currency-dollar'].call(this, undefined));212 equal(false, $.validator.methods['validate-currency-dollar'].call(this, " "));213 equal(true, $.validator.methods['validate-currency-dollar'].call(this, "$123"));214 equal(true, $.validator.methods['validate-currency-dollar'].call(this, "$1,123.00"));215 equal(true, $.validator.methods['validate-currency-dollar'].call(this, "$1234"));216 equal(false, $.validator.methods['validate-currency-dollar'].call(this, "$1234.1234"));217});218test( "testValidateNotNegativeNumber", function() {219 expect(11);220 equal(true, $.validator.methods['validate-not-negative-number'].call(this, ""));221 equal(true, $.validator.methods['validate-not-negative-number'].call(this, null));222 equal(true, $.validator.methods['validate-not-negative-number'].call(this, undefined));223 equal(false, $.validator.methods['validate-not-negative-number'].call(this, " "));224 equal(true, $.validator.methods['validate-not-negative-number'].call(this, "0"));225 equal(true, $.validator.methods['validate-not-negative-number'].call(this, "1"));226 equal(true, $.validator.methods['validate-not-negative-number'].call(this, "1234"));227 equal(true, $.validator.methods['validate-not-negative-number'].call(this, "1,234.1234"));228 equal(false, $.validator.methods['validate-not-negative-number'].call(this, "-1"));229 equal(false, $.validator.methods['validate-not-negative-number'].call(this, "-1e"));230 equal(false, $.validator.methods['validate-not-negative-number'].call(this, "-1,234.1234"));231});232test( "testValidateGreaterThanZero", function() {233 expect(11);234 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, ""));235 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, null));236 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, undefined));237 equal(false, $.validator.methods['validate-greater-than-zero'].call(this, " "));238 equal(false, $.validator.methods['validate-greater-than-zero'].call(this, "0"));239 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, "1"));240 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, "1234"));241 equal(true, $.validator.methods['validate-greater-than-zero'].call(this, "1,234.1234"));242 equal(false, $.validator.methods['validate-greater-than-zero'].call(this, "-1"));243 equal(false, $.validator.methods['validate-greater-than-zero'].call(this, "-1e"));244 equal(false, $.validator.methods['validate-greater-than-zero'].call(this, "-1,234.1234"));245});246test( "testValidateCssLength", function() {247 expect(11);248 equal(true, $.validator.methods['validate-css-length'].call(this, ""));249 equal(true, $.validator.methods['validate-css-length'].call(this, null));250 equal(true, $.validator.methods['validate-css-length'].call(this, undefined));251 equal(false, $.validator.methods['validate-css-length'].call(this, " "));252 equal(false, $.validator.methods['validate-css-length'].call(this, "0"));253 equal(true, $.validator.methods['validate-css-length'].call(this, "1"));254 equal(true, $.validator.methods['validate-css-length'].call(this, "1234"));255 equal(true, $.validator.methods['validate-css-length'].call(this, "1,234.1234"));256 equal(false, $.validator.methods['validate-css-length'].call(this, "-1"));257 equal(false, $.validator.methods['validate-css-length'].call(this, "-1e"));258 equal(false, $.validator.methods['validate-css-length'].call(this, "-1,234.1234"));259});260test( "testValidateData", function() {261 expect(9);262 equal(true, $.validator.methods['validate-data'].call(this, ""));263 equal(true, $.validator.methods['validate-data'].call(this, null));264 equal(true, $.validator.methods['validate-data'].call(this, undefined));265 equal(false, $.validator.methods['validate-data'].call(this, " "));266 equal(false, $.validator.methods['validate-data'].call(this, "123abc"));267 equal(true, $.validator.methods['validate-data'].call(this, "abc"));268 equal(false, $.validator.methods['validate-data'].call(this, " abc"));269 equal(true, $.validator.methods['validate-data'].call(this, "abc123"));270 equal(false, $.validator.methods['validate-data'].call(this, "abc-123"));271});272test( "testValidateOneRequiredByName", function() {273 expect(4);274 var radio = $('<input type="radio" name="radio"/>');275 radio.appendTo("#qunit-fixture");276 ok(!$.validator.methods['validate-one-required-by-name'].call(this,277 null, radio[0]));278 var radio2 = $('<input type="radio" name="radio" checked/>');279 radio2.appendTo("#qunit-fixture");280 ok($.validator.methods['validate-one-required-by-name'].call(this,281 null, radio2[0]));282 var checkbox = $('<input type="checkbox" name="checkbox"/>');283 checkbox.appendTo("#qunit-fixture");284 ok(!$.validator.methods['validate-one-required-by-name'].call(this,285 null, checkbox[0]));286 var checkbox2 = $('<input type="checkbox" name="checkbox" checked/>');287 checkbox2.appendTo("#qunit-fixture");288 ok($.validator.methods['validate-one-required-by-name'].call(this,289 null, checkbox2[0]));290});291test( "testLessThanEqualsTo", function() {292 expect(5);293 var elm1 = $('<input type="text" value=6 id="element1" />');294 var elm2 = $('<input type="text" value=5 id="element2" />');295 ok(!$.validator.methods['less-than-equals-to'].call(this, elm1[0].value,296 elm1, elm2));297 elm1[0].value = 4;298 ok($.validator.methods['less-than-equals-to'].call(this, elm1[0].value,299 elm1, elm2));300 var elm3 = $('<input type="text" id="element3" />');301 var elm4= $('<input type="text" value=5 id="element4" />');302 ok($.validator.methods['less-than-equals-to'].call(this, elm3[0].value,303 elm3, elm4));304 var elm5 = $('<input type="text" id="element6" />');305 var elm6= $('<input type="text" value=6 id="element5" />');306 ok($.validator.methods['less-than-equals-to'].call(this, elm5[0].value,307 elm5, elm6));308 var elm7 = $('<input type="text" value=20 id="element7" />');309 var elm8= $('<input type="text" value=100 id="element8" />');310 ok($.validator.methods['less-than-equals-to'].call(this, elm7[0].value,311 elm7, elm8));312});313test( "testGreaterThanEqualsTo", function() {314 expect(5);315 var elm1 = $('<input type="text" value=6 id="element1" />');316 var elm2 = $('<input type="text" value=7 id="element2" />');317 ok(!$.validator.methods['greater-than-equals-to'].call(this, elm1[0].value,318 elm1, elm2));319 elm1[0].value = 9;320 ok($.validator.methods['greater-than-equals-to'].call(this, elm1[0].value,321 elm1, elm2));322 var elm3 = $('<input type="text" id="element3" />');323 var elm4= $('<input type="text" value=5 id="element4" />');324 ok($.validator.methods['greater-than-equals-to'].call(this, elm3[0].value,325 elm3, elm4));326 var elm5 = $('<input type="text" id="element6" />');327 var elm6= $('<input type="text" value=6 id="element5" />');328 ok($.validator.methods['greater-than-equals-to'].call(this, elm5[0].value,329 elm5, elm6));330 var elm7 = $('<input type="text" value=100 id="element7" />');331 var elm8= $('<input type="text" value=20 id="element8" />');332 ok($.validator.methods['greater-than-equals-to'].call(this, elm7[0].value,333 elm7, elm8));334});335test( "testValidateGroupedQty", function() {336 expect(5);337 var div1 = $('<div id="div1"/>');338 $('<input type="text"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")339 .appendTo(div1);340 $('<input type="text"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")341 .appendTo(div1);342 $('<input type="text"/>').appendTo(div1);343 ok(!$.validator.methods['validate-grouped-qty'].call(this, null, null, div1[0]));344 var div2 = $('<div id="div2"/>');345 $('<input type="text"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")346 .appendTo(div2);347 $('<input type="text" value="a"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")348 .appendTo(div2);349 $('<input type="text"/>').appendTo(div2);350 ok(!$.validator.methods['validate-grouped-qty'].call(this, null, null, div2[0]));351 var div3 = $('<div id="div3"/>');352 $('<input type="text"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")353 .appendTo(div3);354 $('<input type="text" value="-6"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")355 .appendTo(div3);356 $('<input type="text"/>').appendTo(div3);357 ok(!$.validator.methods['validate-grouped-qty'].call(this, null, null, div3[0]));358 var div4 = $('<div id="div4"/>');359 $('<input type="text"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")360 .appendTo(div4);361 $('<input type="text" value="6"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")362 .appendTo(div4);363 $('<input type="text"/>').appendTo(div4);364 ok($.validator.methods['validate-grouped-qty'].call(this, null, null, div4[0]));365 var div5 = $('<div id="div5"/>');366 $('<input type="text" value=""/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")367 .appendTo(div5);368 $('<input type="text" value="6"/>').attr("data-validate","{'validate-grouped-qty':'#super-product-table'}")369 .appendTo(div5);370 $('<input type="text"/>').appendTo(div5);371 ok($.validator.methods['validate-grouped-qty'].call(this, null, null, div5[0]));372});373test( "testValidateCCTypeSelect", function() {374 expect(14);375 var visaValid = $('<input id="visa-valid" type="text" value="4916808263499650"/>');376 var visaInvalid = $('<input id="visa-invalid" type="text" value="1234567890123456"/>');377 var mcValid = $('<input id="mc-valid" type="text" value="5203731841177490"/>');378 var mcInvalid = $('<input id="mc-invalid" type="text" value="1111222233334444"/>');379 var aeValid = $('<input id="ae-valid" type="text" value="376244899619217"/>');380 var aeInvalid = $('<input id="ae-invalid" type="text" value="123451234512345"/>');381 var diValid = $('<input id="di-valid" type="text" value="6011050000000009"/>');382 var diInvalid = $('<input id="di-invalid" type="text" value="6011199900000005"/>');383 var dnValid = $('<input id="dn-valid" type="text" value="3095434000000001"/>');384 var dnInvalid = $('<input id="dn-invalid" type="text" value="3799999900000003"/>');385 var jcbValid = $('<input id="jcb-valid" type="text" value="3528000000000007"/>');386 var jcbInvalid = $('<input id="jcb-invalid" type="text" value="359000001111118"/>');387 var upValid = $('<input id="up-valid" type="text" value="6221260000000000"/>');388 var upInvalid = $('<input id="up-invalid" type="text" value="6229260000000002"/>');389 ok($.validator.methods['validate-cc-type-select'].call(this, 'VI', null, visaValid));390 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'VI', null, visaInvalid));391 ok($.validator.methods['validate-cc-type-select'].call(this, 'MC', null, mcValid));392 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'MC', null, mcInvalid));393 ok($.validator.methods['validate-cc-type-select'].call(this, 'AE', null, aeValid));394 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'AE', null, aeInvalid));395 ok($.validator.methods['validate-cc-type-select'].call(this, 'DI', null, diValid));396 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'DI', null, diInvalid));397 ok($.validator.methods['validate-cc-type-select'].call(this, 'DN', null, dnValid));398 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'DN', null, dnInvalid));399 ok($.validator.methods['validate-cc-type-select'].call(this, 'JCB', null, jcbValid));400 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'JCB', null, jcbInvalid));401 ok($.validator.methods['validate-cc-type-select'].call(this, 'UP', null, upValid));402 ok(!$.validator.methods['validate-cc-type-select'].call(this, 'UP', null, upInvalid));403});404test( "testValidateCCNumber", function() {405 expect(37);406 ok($.validator.methods['validate-cc-number'].call(this, '4916835098995909', null, null));407 ok($.validator.methods['validate-cc-number'].call(this, '5265071363284878', null, null));408 ok($.validator.methods['validate-cc-number'].call(this, '6011120623356953', null, null));409 ok($.validator.methods['validate-cc-number'].call(this, '371293266574617', null, null));410 ok(!$.validator.methods['validate-cc-number'].call(this, '4916835098995901', null, null));411 ok(!$.validator.methods['validate-cc-number'].call(this, '5265071363284870', null, null));412 ok(!$.validator.methods['validate-cc-number'].call(this, '6011120623356951', null, null));413 ok(!$.validator.methods['validate-cc-number'].call(this, '371293266574619', null, null));414 ok($.validator.methods['validate-cc-number'].call(this, '2221220000000003', null, null));415 ok(!$.validator.methods['validate-cc-number'].call(this, '2721220000000008', null, null));416 ok($.validator.methods['validate-cc-number'].call(this, '601109020000000003', null, null));417 ok(!$.validator.methods['validate-cc-number'].call(this, '6011111144444444', null, null));418 ok($.validator.methods['validate-cc-number'].call(this, '6011222233334444', null, null));419 ok(!$.validator.methods['validate-cc-number'].call(this, '6011522233334447', null, null));420 ok($.validator.methods['validate-cc-number'].call(this, '601174455555553', null, null));421 ok(!$.validator.methods['validate-cc-number'].call(this, '6011745555555550', null, null));422 ok($.validator.methods['validate-cc-number'].call(this, '601177455555556', null, null));423 ok(!$.validator.methods['validate-cc-number'].call(this, '601182455555556', null, null));424 ok($.validator.methods['validate-cc-number'].call(this, '601187999555558', null, null));425 ok(!$.validator.methods['validate-cc-number'].call(this, '601287999555556', null, null));426 ok($.validator.methods['validate-cc-number'].call(this, '6444444444444443', null, null));427 ok(!$.validator.methods['validate-cc-number'].call(this, '6644444444444441', null, null));428 ok($.validator.methods['validate-cc-number'].call(this, '3044444444444444', null, null));429 ok(!$.validator.methods['validate-cc-number'].call(this, '3064444444444449', null, null));430 ok($.validator.methods['validate-cc-number'].call(this, '3095444444444442', null, null));431 ok(!$.validator.methods['validate-cc-number'].call(this, '3096444444444441', null, null));432 ok($.validator.methods['validate-cc-number'].call(this, '3696444444444445', null, null));433 ok(!$.validator.methods['validate-cc-number'].call(this, '3796444444444444', null, null));434 ok($.validator.methods['validate-cc-number'].call(this, '3896444444444443', null, null));435 ok($.validator.methods['validate-cc-number'].call(this, '3528444444444449', null, null));436 ok(!$.validator.methods['validate-cc-number'].call(this, '3529444444444448', null, null));437 ok($.validator.methods['validate-cc-number'].call(this, '6221262244444440', null, null));438 ok(!$.validator.methods['validate-cc-number'].call(this, '6229981111111111', null, null));439 ok($.validator.methods['validate-cc-number'].call(this, '6249981111111117', null, null));440 ok(!$.validator.methods['validate-cc-number'].call(this, '6279981111111110', null, null));441 ok($.validator.methods['validate-cc-number'].call(this, '6282981111111115', null, null));442 ok(!$.validator.methods['validate-cc-number'].call(this, '6289981111111118', null, null));443});444test( "testValidateCCType", function() {445 expect(14);446 var select = $('<select id="cc-type">' +447 '<option value="">' +448 '</option><option value="VI">' +449 '</option><option value="MC">' +450 '</option><option value="AE">' +451 '</option><option value="DI">' +452 '</option><option value="DN">' +453 '</option><option value="JCB">' +454 '</option><option value="UP">' +455 '</option>' +456 '</select>');457 select.val('VI');458 ok($.validator.methods['validate-cc-type'].call(this, '4916835098995909', null, select));459 ok(!$.validator.methods['validate-cc-type'].call(this, '5265071363284878', null, select));460 select.val('MC');461 ok($.validator.methods['validate-cc-type'].call(this, '5265071363284878', null, select));462 ok(!$.validator.methods['validate-cc-type'].call(this, '4916835098995909', null, select));463 select.val('AE');464 ok($.validator.methods['validate-cc-type'].call(this, '371293266574617', null, select));465 ok(!$.validator.methods['validate-cc-type'].call(this, '5265071363284878', null, select));466 select.val('DI');467 ok($.validator.methods['validate-cc-type'].call(this, '6011050000000009', null, select));468 ok(!$.validator.methods['validate-cc-type'].call(this, '371293266574617', null, select));469 select.val('DN');470 ok($.validator.methods['validate-cc-type'].call(this, '3095434000000001', null, select));471 ok(!$.validator.methods['validate-cc-type'].call(this, '6011050000000009', null, select));472 select.val('JCB');473 ok($.validator.methods['validate-cc-type'].call(this, '3528000000000007', null, select));474 ok(!$.validator.methods['validate-cc-type'].call(this, '3095434000000001', null, select));475 select.val('UP');476 ok($.validator.methods['validate-cc-type'].call(this, '6221260000000000', null, select));477 ok(!$.validator.methods['validate-cc-type'].call(this, '3528000000000007', null, select));478});479test( "testValidateCCExp", function() {480 expect(3);481 var year = $('<input id="year" type="text" value="4916808263499650"/>'),482 currentTime = new Date(),483 currentMonth = currentTime.getMonth() + 1,484 currentYear = currentTime.getFullYear();485 year.val(currentYear);486 if (currentMonth > 1) {487 ok(!$.validator.methods['validate-cc-exp'].call(this, currentMonth - 1, null, year));488 }489 ok($.validator.methods['validate-cc-exp'].call(this, currentMonth, null, year));490 year.val(currentYear + 1);491 ok($.validator.methods['validate-cc-exp'].call(this, currentMonth, null, year));492});493test( "testValidateCCCvn", function() {494 expect(8);495 var ccType = $('<select id="cc-type">'+496 '<option value=""></option>'+497 '<option value="VI"></option>'+498 '<option value="MC"></option>'+499 '<option value="AE"></option>'+500 '<option value="DI"></option>'+501 '</select>');502 ccType.val('VI');503 ok($.validator.methods['validate-cc-cvn'].call(this, '123', null, ccType));504 ok(!$.validator.methods['validate-cc-cvn'].call(this, '1234', null, ccType));505 ccType.val('MC');506 ok($.validator.methods['validate-cc-cvn'].call(this, '123', null, ccType));507 ok(!$.validator.methods['validate-cc-cvn'].call(this, '1234', null, ccType));508 ccType.val('AE');509 ok($.validator.methods['validate-cc-cvn'].call(this, '1234', null, ccType));510 ok(!$.validator.methods['validate-cc-cvn'].call(this, '123', null, ccType));511 ccType.val('DI');512 ok($.validator.methods['validate-cc-cvn'].call(this, '123', null, ccType));513 ok(!$.validator.methods['validate-cc-cvn'].call(this, '1234', null, ccType));514});515test( "testValidateNumberRange", function() {516 expect(14);517 ok($.validator.methods['validate-number-range'].call(this, '-1', null, null));518 ok($.validator.methods['validate-number-range'].call(this, '1', null, null));519 ok($.validator.methods['validate-number-range'].call(this, '', null, null));520 ok($.validator.methods['validate-number-range'].call(this, null, null, null));521 ok($.validator.methods['validate-number-range'].call(this, '0', null, null));522 ok(!$.validator.methods['validate-number-range'].call(this, 'asds', null, null));523 ok($.validator.methods['validate-number-range'].call(this, '10', null, '10-20.06'));524 ok($.validator.methods['validate-number-range'].call(this, '15', null, '10-20.06'));525 ok(!$.validator.methods['validate-number-range'].call(this, '1', null, '10-20.06'));526 ok(!$.validator.methods['validate-number-range'].call(this, '30', null, '10-20.06'));527 var el1 = $('<input type="text" value="" class="validate-number-range number-range-10-20 number-range-10-100.20">').get(0);528 ok($.validator.methods['validate-number-range'].call(this, '10', el1, null));529 ok($.validator.methods['validate-number-range'].call(this, '15', el1, null));530 ok(!$.validator.methods['validate-number-range'].call(this, '1', el1, null));531 ok($.validator.methods['validate-number-range'].call(this, '30', el1, null));532});533test( "testValidateDigitsRange", function() {534 expect(15);535 ok($.validator.methods['validate-digits-range'].call(this, '-1', null, null));536 ok($.validator.methods['validate-digits-range'].call(this, '1', null, null));537 ok($.validator.methods['validate-digits-range'].call(this, '', null, null));538 ok($.validator.methods['validate-digits-range'].call(this, null, null, null));539 ok($.validator.methods['validate-digits-range'].call(this, '0', null, null));540 ok(!$.validator.methods['validate-digits-range'].call(this, 'asds', null, null));541 ok($.validator.methods['validate-digits-range'].call(this, '10', null, '10-20'));542 ok($.validator.methods['validate-digits-range'].call(this, '15', null, '10-20'));543 ok(!$.validator.methods['validate-digits-range'].call(this, '1', null, '10-20'));544 ok(!$.validator.methods['validate-digits-range'].call(this, '30', null, '10-20'));545 ok($.validator.methods['validate-digits-range'].call(this, '30', null, '10-20.06'));546 var el1 = $('<input type="text" value="" class="validate-digits-range digits-range-10-20 digits-range-10-100.20">').get(0);547 ok($.validator.methods['validate-digits-range'].call(this, '10', el1, null));548 ok($.validator.methods['validate-digits-range'].call(this, '15', el1, null));549 ok(!$.validator.methods['validate-digits-range'].call(this, '1', el1, null));550 ok(!$.validator.methods['validate-digits-range'].call(this, '30', el1, null));...

Full Screen

Full Screen

flow.js

Source:flow.js Github

copy

Full Screen

1"use strict";2var _utils = require("./utils");3const defineInterfaceishType = (name, typeParameterType = "TypeParameterDeclaration") => {4 (0, _utils.default)(name, {5 builder: ["id", "typeParameters", "extends", "body"],6 visitor: ["id", "typeParameters", "extends", "mixins", "implements", "body"],7 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],8 fields: {9 id: (0, _utils.validateType)("Identifier"),10 typeParameters: (0, _utils.validateOptionalType)(typeParameterType),11 extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")),12 mixins: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")),13 implements: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ClassImplements")),14 body: (0, _utils.validateType)("ObjectTypeAnnotation")15 }16 });17};18(0, _utils.default)("AnyTypeAnnotation", {19 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]20});21(0, _utils.default)("ArrayTypeAnnotation", {22 visitor: ["elementType"],23 aliases: ["Flow", "FlowType"],24 fields: {25 elementType: (0, _utils.validateType)("FlowType")26 }27});28(0, _utils.default)("BooleanTypeAnnotation", {29 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]30});31(0, _utils.default)("BooleanLiteralTypeAnnotation", {32 builder: ["value"],33 aliases: ["Flow", "FlowType"],34 fields: {35 value: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))36 }37});38(0, _utils.default)("NullLiteralTypeAnnotation", {39 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]40});41(0, _utils.default)("ClassImplements", {42 visitor: ["id", "typeParameters"],43 aliases: ["Flow"],44 fields: {45 id: (0, _utils.validateType)("Identifier"),46 typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation")47 }48});49defineInterfaceishType("DeclareClass");50(0, _utils.default)("DeclareFunction", {51 visitor: ["id"],52 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],53 fields: {54 id: (0, _utils.validateType)("Identifier"),55 predicate: (0, _utils.validateOptionalType)("DeclaredPredicate")56 }57});58defineInterfaceishType("DeclareInterface");59(0, _utils.default)("DeclareModule", {60 builder: ["id", "body", "kind"],61 visitor: ["id", "body"],62 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],63 fields: {64 id: (0, _utils.validateType)(["Identifier", "StringLiteral"]),65 body: (0, _utils.validateType)("BlockStatement"),66 kind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("CommonJS", "ES"))67 }68});69(0, _utils.default)("DeclareModuleExports", {70 visitor: ["typeAnnotation"],71 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],72 fields: {73 typeAnnotation: (0, _utils.validateType)("TypeAnnotation")74 }75});76(0, _utils.default)("DeclareTypeAlias", {77 visitor: ["id", "typeParameters", "right"],78 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],79 fields: {80 id: (0, _utils.validateType)("Identifier"),81 typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"),82 right: (0, _utils.validateType)("FlowType")83 }84});85(0, _utils.default)("DeclareOpaqueType", {86 visitor: ["id", "typeParameters", "supertype"],87 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],88 fields: {89 id: (0, _utils.validateType)("Identifier"),90 typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"),91 supertype: (0, _utils.validateOptionalType)("FlowType"),92 impltype: (0, _utils.validateOptionalType)("FlowType")93 }94});95(0, _utils.default)("DeclareVariable", {96 visitor: ["id"],97 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],98 fields: {99 id: (0, _utils.validateType)("Identifier")100 }101});102(0, _utils.default)("DeclareExportDeclaration", {103 visitor: ["declaration", "specifiers", "source"],104 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],105 fields: {106 declaration: (0, _utils.validateOptionalType)("Flow"),107 specifiers: (0, _utils.validateOptional)((0, _utils.arrayOfType)(["ExportSpecifier", "ExportNamespaceSpecifier"])),108 source: (0, _utils.validateOptionalType)("StringLiteral"),109 default: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean"))110 }111});112(0, _utils.default)("DeclareExportAllDeclaration", {113 visitor: ["source"],114 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],115 fields: {116 source: (0, _utils.validateType)("StringLiteral"),117 exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value"))118 }119});120(0, _utils.default)("DeclaredPredicate", {121 visitor: ["value"],122 aliases: ["Flow", "FlowPredicate"],123 fields: {124 value: (0, _utils.validateType)("Flow")125 }126});127(0, _utils.default)("ExistsTypeAnnotation", {128 aliases: ["Flow", "FlowType"]129});130(0, _utils.default)("FunctionTypeAnnotation", {131 visitor: ["typeParameters", "params", "rest", "returnType"],132 aliases: ["Flow", "FlowType"],133 fields: {134 typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"),135 params: (0, _utils.validate)((0, _utils.arrayOfType)("FunctionTypeParam")),136 rest: (0, _utils.validateOptionalType)("FunctionTypeParam"),137 this: (0, _utils.validateOptionalType)("FunctionTypeParam"),138 returnType: (0, _utils.validateType)("FlowType")139 }140});141(0, _utils.default)("FunctionTypeParam", {142 visitor: ["name", "typeAnnotation"],143 aliases: ["Flow"],144 fields: {145 name: (0, _utils.validateOptionalType)("Identifier"),146 typeAnnotation: (0, _utils.validateType)("FlowType"),147 optional: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean"))148 }149});150(0, _utils.default)("GenericTypeAnnotation", {151 visitor: ["id", "typeParameters"],152 aliases: ["Flow", "FlowType"],153 fields: {154 id: (0, _utils.validateType)(["Identifier", "QualifiedTypeIdentifier"]),155 typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation")156 }157});158(0, _utils.default)("InferredPredicate", {159 aliases: ["Flow", "FlowPredicate"]160});161(0, _utils.default)("InterfaceExtends", {162 visitor: ["id", "typeParameters"],163 aliases: ["Flow"],164 fields: {165 id: (0, _utils.validateType)(["Identifier", "QualifiedTypeIdentifier"]),166 typeParameters: (0, _utils.validateOptionalType)("TypeParameterInstantiation")167 }168});169defineInterfaceishType("InterfaceDeclaration");170(0, _utils.default)("InterfaceTypeAnnotation", {171 visitor: ["extends", "body"],172 aliases: ["Flow", "FlowType"],173 fields: {174 extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("InterfaceExtends")),175 body: (0, _utils.validateType)("ObjectTypeAnnotation")176 }177});178(0, _utils.default)("IntersectionTypeAnnotation", {179 visitor: ["types"],180 aliases: ["Flow", "FlowType"],181 fields: {182 types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType"))183 }184});185(0, _utils.default)("MixedTypeAnnotation", {186 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]187});188(0, _utils.default)("EmptyTypeAnnotation", {189 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]190});191(0, _utils.default)("NullableTypeAnnotation", {192 visitor: ["typeAnnotation"],193 aliases: ["Flow", "FlowType"],194 fields: {195 typeAnnotation: (0, _utils.validateType)("FlowType")196 }197});198(0, _utils.default)("NumberLiteralTypeAnnotation", {199 builder: ["value"],200 aliases: ["Flow", "FlowType"],201 fields: {202 value: (0, _utils.validate)((0, _utils.assertValueType)("number"))203 }204});205(0, _utils.default)("NumberTypeAnnotation", {206 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]207});208(0, _utils.default)("ObjectTypeAnnotation", {209 visitor: ["properties", "indexers", "callProperties", "internalSlots"],210 aliases: ["Flow", "FlowType"],211 builder: ["properties", "indexers", "callProperties", "internalSlots", "exact"],212 fields: {213 properties: (0, _utils.validate)((0, _utils.arrayOfType)(["ObjectTypeProperty", "ObjectTypeSpreadProperty"])),214 indexers: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ObjectTypeIndexer")),215 callProperties: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ObjectTypeCallProperty")),216 internalSlots: (0, _utils.validateOptional)((0, _utils.arrayOfType)("ObjectTypeInternalSlot")),217 exact: {218 validate: (0, _utils.assertValueType)("boolean"),219 default: false220 },221 inexact: (0, _utils.validateOptional)((0, _utils.assertValueType)("boolean"))222 }223});224(0, _utils.default)("ObjectTypeInternalSlot", {225 visitor: ["id", "value", "optional", "static", "method"],226 aliases: ["Flow", "UserWhitespacable"],227 fields: {228 id: (0, _utils.validateType)("Identifier"),229 value: (0, _utils.validateType)("FlowType"),230 optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),231 static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),232 method: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))233 }234});235(0, _utils.default)("ObjectTypeCallProperty", {236 visitor: ["value"],237 aliases: ["Flow", "UserWhitespacable"],238 fields: {239 value: (0, _utils.validateType)("FlowType"),240 static: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))241 }242});243(0, _utils.default)("ObjectTypeIndexer", {244 visitor: ["id", "key", "value", "variance"],245 aliases: ["Flow", "UserWhitespacable"],246 fields: {247 id: (0, _utils.validateOptionalType)("Identifier"),248 key: (0, _utils.validateType)("FlowType"),249 value: (0, _utils.validateType)("FlowType"),250 static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),251 variance: (0, _utils.validateOptionalType)("Variance")252 }253});254(0, _utils.default)("ObjectTypeProperty", {255 visitor: ["key", "value", "variance"],256 aliases: ["Flow", "UserWhitespacable"],257 fields: {258 key: (0, _utils.validateType)(["Identifier", "StringLiteral"]),259 value: (0, _utils.validateType)("FlowType"),260 kind: (0, _utils.validate)((0, _utils.assertOneOf)("init", "get", "set")),261 static: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),262 proto: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),263 optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),264 variance: (0, _utils.validateOptionalType)("Variance"),265 method: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))266 }267});268(0, _utils.default)("ObjectTypeSpreadProperty", {269 visitor: ["argument"],270 aliases: ["Flow", "UserWhitespacable"],271 fields: {272 argument: (0, _utils.validateType)("FlowType")273 }274});275(0, _utils.default)("OpaqueType", {276 visitor: ["id", "typeParameters", "supertype", "impltype"],277 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],278 fields: {279 id: (0, _utils.validateType)("Identifier"),280 typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"),281 supertype: (0, _utils.validateOptionalType)("FlowType"),282 impltype: (0, _utils.validateType)("FlowType")283 }284});285(0, _utils.default)("QualifiedTypeIdentifier", {286 visitor: ["id", "qualification"],287 aliases: ["Flow"],288 fields: {289 id: (0, _utils.validateType)("Identifier"),290 qualification: (0, _utils.validateType)(["Identifier", "QualifiedTypeIdentifier"])291 }292});293(0, _utils.default)("StringLiteralTypeAnnotation", {294 builder: ["value"],295 aliases: ["Flow", "FlowType"],296 fields: {297 value: (0, _utils.validate)((0, _utils.assertValueType)("string"))298 }299});300(0, _utils.default)("StringTypeAnnotation", {301 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]302});303(0, _utils.default)("SymbolTypeAnnotation", {304 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]305});306(0, _utils.default)("ThisTypeAnnotation", {307 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]308});309(0, _utils.default)("TupleTypeAnnotation", {310 visitor: ["types"],311 aliases: ["Flow", "FlowType"],312 fields: {313 types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType"))314 }315});316(0, _utils.default)("TypeofTypeAnnotation", {317 visitor: ["argument"],318 aliases: ["Flow", "FlowType"],319 fields: {320 argument: (0, _utils.validateType)("FlowType")321 }322});323(0, _utils.default)("TypeAlias", {324 visitor: ["id", "typeParameters", "right"],325 aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],326 fields: {327 id: (0, _utils.validateType)("Identifier"),328 typeParameters: (0, _utils.validateOptionalType)("TypeParameterDeclaration"),329 right: (0, _utils.validateType)("FlowType")330 }331});332(0, _utils.default)("TypeAnnotation", {333 aliases: ["Flow"],334 visitor: ["typeAnnotation"],335 fields: {336 typeAnnotation: (0, _utils.validateType)("FlowType")337 }338});339(0, _utils.default)("TypeCastExpression", {340 visitor: ["expression", "typeAnnotation"],341 aliases: ["Flow", "ExpressionWrapper", "Expression"],342 fields: {343 expression: (0, _utils.validateType)("Expression"),344 typeAnnotation: (0, _utils.validateType)("TypeAnnotation")345 }346});347(0, _utils.default)("TypeParameter", {348 aliases: ["Flow"],349 visitor: ["bound", "default", "variance"],350 fields: {351 name: (0, _utils.validate)((0, _utils.assertValueType)("string")),352 bound: (0, _utils.validateOptionalType)("TypeAnnotation"),353 default: (0, _utils.validateOptionalType)("FlowType"),354 variance: (0, _utils.validateOptionalType)("Variance")355 }356});357(0, _utils.default)("TypeParameterDeclaration", {358 aliases: ["Flow"],359 visitor: ["params"],360 fields: {361 params: (0, _utils.validate)((0, _utils.arrayOfType)("TypeParameter"))362 }363});364(0, _utils.default)("TypeParameterInstantiation", {365 aliases: ["Flow"],366 visitor: ["params"],367 fields: {368 params: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType"))369 }370});371(0, _utils.default)("UnionTypeAnnotation", {372 visitor: ["types"],373 aliases: ["Flow", "FlowType"],374 fields: {375 types: (0, _utils.validate)((0, _utils.arrayOfType)("FlowType"))376 }377});378(0, _utils.default)("Variance", {379 aliases: ["Flow"],380 builder: ["kind"],381 fields: {382 kind: (0, _utils.validate)((0, _utils.assertOneOf)("minus", "plus"))383 }384});385(0, _utils.default)("VoidTypeAnnotation", {386 aliases: ["Flow", "FlowType", "FlowBaseAnnotation"]387});388(0, _utils.default)("EnumDeclaration", {389 aliases: ["Statement", "Declaration"],390 visitor: ["id", "body"],391 fields: {392 id: (0, _utils.validateType)("Identifier"),393 body: (0, _utils.validateType)(["EnumBooleanBody", "EnumNumberBody", "EnumStringBody", "EnumSymbolBody"])394 }395});396(0, _utils.default)("EnumBooleanBody", {397 aliases: ["EnumBody"],398 visitor: ["members"],399 fields: {400 explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),401 members: (0, _utils.validateArrayOfType)("EnumBooleanMember"),402 hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))403 }404});405(0, _utils.default)("EnumNumberBody", {406 aliases: ["EnumBody"],407 visitor: ["members"],408 fields: {409 explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),410 members: (0, _utils.validateArrayOfType)("EnumNumberMember"),411 hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))412 }413});414(0, _utils.default)("EnumStringBody", {415 aliases: ["EnumBody"],416 visitor: ["members"],417 fields: {418 explicitType: (0, _utils.validate)((0, _utils.assertValueType)("boolean")),419 members: (0, _utils.validateArrayOfType)(["EnumStringMember", "EnumDefaultedMember"]),420 hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))421 }422});423(0, _utils.default)("EnumSymbolBody", {424 aliases: ["EnumBody"],425 visitor: ["members"],426 fields: {427 members: (0, _utils.validateArrayOfType)("EnumDefaultedMember"),428 hasUnknownMembers: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))429 }430});431(0, _utils.default)("EnumBooleanMember", {432 aliases: ["EnumMember"],433 visitor: ["id"],434 fields: {435 id: (0, _utils.validateType)("Identifier"),436 init: (0, _utils.validateType)("BooleanLiteral")437 }438});439(0, _utils.default)("EnumNumberMember", {440 aliases: ["EnumMember"],441 visitor: ["id", "init"],442 fields: {443 id: (0, _utils.validateType)("Identifier"),444 init: (0, _utils.validateType)("NumericLiteral")445 }446});447(0, _utils.default)("EnumStringMember", {448 aliases: ["EnumMember"],449 visitor: ["id", "init"],450 fields: {451 id: (0, _utils.validateType)("Identifier"),452 init: (0, _utils.validateType)("StringLiteral")453 }454});455(0, _utils.default)("EnumDefaultedMember", {456 aliases: ["EnumMember"],457 visitor: ["id"],458 fields: {459 id: (0, _utils.validateType)("Identifier")460 }461});462(0, _utils.default)("IndexedAccessType", {463 visitor: ["objectType", "indexType"],464 aliases: ["Flow", "FlowType"],465 fields: {466 objectType: (0, _utils.validateType)("FlowType"),467 indexType: (0, _utils.validateType)("FlowType")468 }469});470(0, _utils.default)("OptionalIndexedAccessType", {471 visitor: ["objectType", "indexType"],472 aliases: ["Flow", "FlowType"],473 fields: {474 objectType: (0, _utils.validateType)("FlowType"),475 indexType: (0, _utils.validateType)("FlowType"),476 optional: (0, _utils.validate)((0, _utils.assertValueType)("boolean"))477 }...

Full Screen

Full Screen

script.validate.js

Source:script.validate.js Github

copy

Full Screen

1// JavaScript Document23/****************************************************************\4Validate Fields V 1.3.15Develped by Alejandro Romero (romero.m.alejandro@gmail.com)67VALIDATION ATRIBUTES:891) validateEmpty: Checks if the field is empty.10 Declaration: 'validateEmpty="Please, complete this field"'11 Data: Text12132) validateMinLength: Checks if the field have a minimum quantity of characters.14 Declaration: 'validateMinLenght="5///Please, enter at least 5 characters"'15 Data: MinVal///Text16173) validateMaxLength: Checks if the field reaches a maximum quantity of characters.18 Declaration: 'validateMaxLenght="25///Please, enter less than 25 characters"'19 Data: MaxVal///Text20214) validateEmail: Checks if the field contains a valid email.22 Declaration: 'validateEmail:"Please, enter a valid email"'23 Data: Text24255) validateOnlyNumbers: Checks if the field contains only numbers.26 Declaration: 'validateOnlyNumbers="Please, enter only numbers"'27 Data: Text28296) validateEqualToField: Checks if the field value is equal to the value of the field specificated in the argument.30 Declaration: 'validateEqualToField="fieldID///Both fields must match"'31 Data: TargetField///Text32337) validateFromFile: Matchs the field value with a file.34 Declaration: 'validateFromFile="process.php///User already exists///otherfieldid///variable:=value"'35 Data: File///Text///(FieldID)///...///(Key:=Value)///...36378) mustBeChecked: Checks if a number of checkboxes are checked.38 Declaration: 'mustBeChecked="1///At least 1 of the checkboxes must be checked"'39 Declaration: 'mustBeChecked="3///Only 3 of the checkboxes can be checked///limited"'40 Declaration: 'mustBeChecked="2///Only 2 of the checkboxes can be checked///strict"'41 Data: Value///Text///(Mode)42 439) validateMaxValue: Checks if the field reaches a maximum numeric value.44 Declaration: 'validateMaxValue="25.07///Please, enter a number lower than 25.07"'45 Data: MaxVal///Text464710) validateMinValue: Checks if the field have a minimum value.48 Declaration: 'validateMinValue="25.07///Please, enter a number higher than 25.07"'49 Data: MaxVal///Text5051\****************************************************************/5253 var validateShowEffect;54 var validateHideEffect;55 var validateErrorClass;56 var validateTag;57 var validateValid;58 var validateElements;59 var validateErrorElements = "";60 var validateDelimiter = '///';61 var validateCheckboxGroups = new Array();6263 function ValidateFields() {64 validateErrorClass = "ErrorText Red";65 validateElements = "input[type!='hidden'],select,textarea";66 validateTag = "div";67 validateValid;68 }6970 ValidateFields.prototype.setErrorClass = function(ErrorClass)71 {72 validateErrorClass = ErrorClass;73 }7475 ValidateFields.prototype.setShowEffect = function(ShowEffect)76 {77 validateShowEffect = ShowEffect;78 }7980 ValidateFields.prototype.setHideEffect = function(HideEffect)81 {82 validateHideEffect = HideEffect;83 }8485 ValidateFields.prototype.setTag = function(Tag)86 {87 validateTag = Tag;88 }8990 ValidateFields.prototype.setElements = function(Elements)91 {92 validateElements = Elements;93 }9495 ValidateFields.prototype.setDelimiter = function(Delimiter)96 {97 validateDelimiter = Delimiter;98 }99100 ValidateFields.prototype.createErrorDivs = function()101 {102 $(validateTag+'[id$="ErrorDiv"]').remove();103 104 $(validateElements).each( function(){105 $(this).parent().append('<'+validateTag+' id="'+$(this).attr("id")+'ErrorDiv" class="'+validateErrorClass+'"></'+validateTag+'>');106 });107 };108109 ValidateFields.prototype.empty = function(object)110 {111 var isempty = false;112113 if($(object).attr("validateEmpty"))114 {115 isempty = ValidateFields.prototype.isEmpty($(object).val()) || !ValidateFields.prototype.isDifferent($(object).val(),$(object).attr("default")) ;116 }117118 return isempty;119 }120121 ValidateFields.prototype.isEmpty = function(value)122 {123 if(!value)124 return true125 else126 return false127 }128129 ValidateFields.prototype.isDifferent = function(value,def)130 {131 if(value!=def)132 return true133 else134 return false135 }136 137 ValidateFields.prototype.minValue = function(object)138 {139 var minVal;140141 minval = false;142 if($(object).attr("validateMinValue") && $(object).val()!="")143 {144 minVal = $(object).attr("validateMinValue").substring(0, $(object).attr("validateMinValue").indexOf(validateDelimiter));145 minval = ValidateFields.prototype.isMinValue(parseFloat($(object).val()),minVal);146 }147 return minval;148 }149150 ValidateFields.prototype.isMinValue = function(value,minVal)151 {152 if(value<minVal)153 return true154 else155 return false156 }157158 ValidateFields.prototype.minLength = function(object)159 {160 var minVal;161162 minlength = false;163 if($(object).attr("validateMinLength") && $(object).val()!="")164 {165 minVal = $(object).attr("validateMinLength").substring(0, $(object).attr("validateMinLength").indexOf(validateDelimiter));166 minlength = ValidateFields.prototype.isMinLength($(object).val().length,minVal);167 }168 return minlength;169 }170171 ValidateFields.prototype.isMinLength = function(value,minVal)172 {173 if(value<minVal)174 return true175 else176 return false177 }178 179 ValidateFields.prototype.maxValue = function(object)180 {181 var maxVal;182183 maxval = false;184 if($(object).attr("validateMaxValue") && $(object).val()!="")185 {186 maxVal = $(object).attr("validateMaxValue").substring(0, $(object).attr("validateMaxValue").indexOf(validateDelimiter));187 maxval = ValidateFields.prototype.isMaxValue(parseFloat($(object).val()),maxVal);188 }189 return maxval;190 }191192 ValidateFields.prototype.isMaxValue = function(value,maxVal)193 {194 if(value>maxVal)195 return true196 else197 return false198 }199200 ValidateFields.prototype.maxLength = function(object)201 {202 var maxVal;203204 maxlength = false;205 if($(object).attr("validateMaxLength") && $(object).val()!="")206 {207 maxVal = $(object).attr("validateMaxLength").substring(0, $(object).attr("validateMaxLength").indexOf(validateDelimiter));208 maxlength = ValidateFields.prototype.isMaxLength($(object).val().length,maxVal);209 }210 return maxlength;211 }212213 ValidateFields.prototype.isMaxLength = function(value,maxVal)214 {215 if(value>maxVal)216 return true217 else218 return false219 }220221 ValidateFields.prototype.equalToField = function(object)222 {223 var field;224 var equal;225226 equal = false;227 if($(object).attr("validateEqualToField"))228 {229 field = $(object).attr("validateEqualToField").substring(0, $(object).attr("validateEqualToField").indexOf(validateDelimiter));230 equal = $(object).val()!=$("#"+field).val();231 }232233 return equal;234 }235236 ValidateFields.prototype.email = function(object)237 {238 var isemail = false;239240 if($(object).attr("validateEmail") && $(object).val()!="")241 {242 isemail = ValidateFields.prototype.isEmail($(object).val());243 }244245 return isemail;246247 }248249 ValidateFields.prototype.isEmail = function(value)250 {251 if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))252 return false253 else254 return true255 }256257 ValidateFields.prototype.onlyNumbers = function(object)258 {259 var isonlynumbers = false;260261 if($(object).attr("validateOnlyNumbers"))262 {263 isonlynumbers = !ValidateFields.prototype.isOnlyNumbers($(object).val());264 }265 return isonlynumbers;266 }267268 ValidateFields.prototype.isOnlyNumbers = function(value)269 {270 if(value.length > 0)271 return !isNaN(parseFloat(value)) && isFinite(value);272 else273 return true;274 }275276 ValidateFields.prototype.isNotFilled = function(object)277 {278 if($("#"+$(object).attr("id")+"ErrorDiv").html()=="")279 return true280 else281 return false282283 }284285 ValidateFields.prototype.fromFile = function(object)286 {287 var fromfile = false;288289 if($(object).attr("validateFromFile"))290 {291 fromfile = ValidateFields.prototype.validateFromFile(object);292 }293 return fromfile;294 }295296 ValidateFields.prototype.validateFromFile = function(object)297 {298299 var validatefromfile = false;300 var properties = $(object).attr("validateFromFile").split(validateDelimiter);301 var value = $(object).val();302 var id = $(object).attr("id");303 var file = properties[0];304 var text = properties[1];305 var string = id+'='+value;306 var field;307308 for(var i=2;i<properties.length;i++)309 {310 field = properties[i].split(":=");311 if(field[1])312 string = string + "&" + field[0] + "=" + field[1];313 else314 string = string + "&" + properties[i] + "=" + $("#"+properties[i]).val();315 }316317 $.ajax({318 type: "POST",319 url: file,320 data: string,321 cache: true,322 async: false,323 success: function(data){324 if(!data)325 validatefromfile = false;326 else327 validatefromfile = true;328 }329 });330331 return validatefromfile;332333334 }335336337 ValidateFields.prototype.mustBeChecked = function(object)338 {339 var name = $(object).attr("name");340 var disabled = $(object).attr("disabled");341 var display = isVisible(object);342 var validateCheckboxGroups = new Array();343344 if($(object).attr("mustBeChecked") && disabled!="disabled" && display && !inArray(name,validateCheckboxGroups))345 {346 validateCheckboxGroups.push(name);347 //$('input[type="checkbox"][name="'+name+'"]').each(function(){if(this!=object)$(this).attr('mustBeChecked','')});348 var properties = $(object).attr("mustBeChecked").split(validateDelimiter);349 var checks = properties[0];350 var mode = properties[2];351 var checked = $('input[type="checkbox"][name="'+name+'"]:checked:not(disabled)').length;352 if(mode) mode = mode.toLowerCase();353 switch(mode)354 {355 case 'strict':356 return checked!=checks;357 break;358359 case 'limited':360 return checked>checks;361 break;362363 default:364 return checked<checks;365 break;366 }367 }else{368 return false;369 }370 }371 372 ValidateFields.prototype.getLastValidation = function()373 {374 return validateErrorElements;375 }376377378 ValidateFields.prototype.validateFields = function(Form)379 {380 validateValid = true;381 validateCheckboxGroups = new Array();382 var validateObject;383384 if(!Form || Form=='*')385 {386 validateObject = $(validateElements);387 }else{388 var elements = validateElements.split(',');389 validateObject = $('#'+Form+' '+elements.join(',#'+Form+' '));390 //alert('#'+Form+' '+elements.join(',#'+Form+' '));391 //validateObject = $('#'+Form+' '+validateElements);392 }393 394 //console.log($('#'+Form+' '+validateElements));395 //validateObject = $('#'+Form).find(validateElements);396 if(!validateObject.attr('id')) validateValid = false;397398399400 validateObject.each(function(){401 if($(this).val()==$(this).attr("default") || !$(this).val()) $(this).val('');402 if(ValidateFields.prototype.validateField(this) && validateValid )403 validateValid = true;404 else405 validateValid = false;406 });407408 return validateValid;409 }410411 ValidateFields.prototype.validateOneField = function(object)412 {413 validateCheckboxGroups = new Array();414 ValidateFields.prototype.validateField(object);415416 }417418 ValidateFields.prototype.validateField = function(object)419 {420 var valid = true421 if(!ValidateFields.prototype.isClearDiv(object)) ValidateFields.prototype.hideDiv(object);422423 if(ValidateFields.prototype.empty(object))424 {425 valid = false;426 $("#"+$(object).attr("id")+"ErrorDiv").html($(object).attr("validateEmpty"));427428 }429 430 if(valid && ValidateFields.prototype.minValue(object))431 {432 valid = false;433 var text = $(object).attr("validateMinValue").substring($(object).attr("validateMinValue").indexOf(validateDelimiter)+validateDelimiter.length);434 $("#"+$(object).attr("id")+"ErrorDiv").html(text);435 }436437 if(valid && ValidateFields.prototype.minLength(object))438 {439 valid = false;440 var text = $(object).attr("validateMinLength").substring($(object).attr("validateMinLength").indexOf(validateDelimiter)+validateDelimiter.length);441 $("#"+$(object).attr("id")+"ErrorDiv").html(text);442 }443 444 if(valid && ValidateFields.prototype.maxValue(object))445 {446 valid = false;447 var text = $(object).attr("validateMaxValue").substring($(object).attr("validateMaxValue").indexOf(validateDelimiter)+validateDelimiter.length);448 $("#"+$(object).attr("id")+"ErrorDiv").html(text);449 }450451 if(valid && ValidateFields.prototype.maxLength(object))452 {453 valid = false;454 var text = $(object).attr("validateMaxLength").substring($(object).attr("validateMaxLength").indexOf(validateDelimiter)+validateDelimiter.length);455 $("#"+$(object).attr("id")+"ErrorDiv").html(text);456 }457458 if(valid && ValidateFields.prototype.email(object))459 {460 valid = false;461 $("#"+$(object).attr("id")+"ErrorDiv").html($(object).attr("validateEmail"));462 }463464 if(valid && ValidateFields.prototype.onlyNumbers(object))465 {466 valid = false;467 $("#"+$(object).attr("id")+"ErrorDiv").html($(object).attr("validateOnlyNumbers"));468 }469470 if(valid && ValidateFields.prototype.equalToField(object))471 {472 valid = false;473 var text = $(object).attr("validateEqualToField").substring($(object).attr("validateEqualToField").indexOf(validateDelimiter)+validateDelimiter.length);474 $("#"+$(object).attr("id")+"ErrorDiv").html(text);475 }476477 if(valid && ValidateFields.prototype.mustBeChecked(object))478 {479 valid = false;480 var text = $(object).attr("mustBeChecked").substring($(object).attr("mustBeChecked").indexOf(validateDelimiter)+validateDelimiter.length);481 //var errormsg = new Message();482 notifyError(text,1500);483 //$("#"+$(object).attr("id")+"ErrorDiv").html(text);484 }485486 if(valid && ValidateFields.prototype.fromFile(object))487 {488 valid = false;489 var text = $(object).attr("validateFromFile").substring($(object).attr("validateFromFile").indexOf(validateDelimiter)+validateDelimiter.length);490 text = text.substring(0,text.indexOf(validateDelimiter))491 $("#"+$(object).attr("id")+"ErrorDiv").html(text);492 }493494 if(!valid) ValidateFields.prototype.showDiv(object);495496 return valid;497 }498499 ValidateFields.prototype.isClearDiv = function(object)500 {501 if($("#"+$(object).attr("id")+"ErrorDiv").html()=="")502 return true503 else504 return false505506 }507508 ValidateFields.prototype.hideDiv = function(object)509 {510 if(!validateValid){511 switch(validateHideEffect)512 {513 case "fade":514 $("#"+$(object).attr("id")+"ErrorDiv").fadeOut(1000);515 break;516 case "slide":517 $("#"+$(object).attr("id")+"ErrorDiv").slideUp();518 break;519 case "hide":520 $("#"+$(object).attr("id")+"ErrorDiv").hide();521 break;522 default:523 $("#"+$(object).attr("id")+"ErrorDiv").hide();524 break;525 }526 }else{527 $("#"+$(object).attr("id")+"ErrorDiv").hide();528 }529 }530531 ValidateFields.prototype.showDiv = function(object)532 {533 validateErrorElements = validateErrorElements + $(object).attr("id") + " ";534 if(!validateValid){535 switch(validateShowEffect)536 {537 case "fade":538 $("#"+$(object).attr("id")+"ErrorDiv").fadeIn(5000);539 break;540 case "slide":541 $("#"+$(object).attr("id")+"ErrorDiv").slideDown();542 break;543 case "hide":544 $("#"+$(object).attr("id")+"ErrorDiv").show();545 break;546 default:547 $("#"+$(object).attr("id")+"ErrorDiv").show();548 break;549 }550 }else{551 $("#"+$(object).attr("id")+"ErrorDiv").show();552 }553 }554555 // Auxiliar Function: Pause556 ValidateFields.prototype.pauseProc = function(millis)557 {558 var date = new Date();559 var curDate = null;560561 do { curDate = new Date(); }562 while(curDate-date < millis); ...

Full Screen

Full Screen

typescript.js

Source:typescript.js Github

copy

Full Screen

1"use strict";2var _utils = require("./utils");3var _core = require("./core");4var _is = require("../validators/is");5const bool = (0, _utils.assertValueType)("boolean");6const tSFunctionTypeAnnotationCommon = {7 returnType: {8 validate: (0, _utils.assertNodeType)("TSTypeAnnotation", "Noop"),9 optional: true10 },11 typeParameters: {12 validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration", "Noop"),13 optional: true14 }15};16(0, _utils.default)("TSParameterProperty", {17 aliases: ["LVal"],18 visitor: ["parameter"],19 fields: {20 accessibility: {21 validate: (0, _utils.assertOneOf)("public", "private", "protected"),22 optional: true23 },24 readonly: {25 validate: (0, _utils.assertValueType)("boolean"),26 optional: true27 },28 parameter: {29 validate: (0, _utils.assertNodeType)("Identifier", "AssignmentPattern")30 },31 override: {32 validate: (0, _utils.assertValueType)("boolean"),33 optional: true34 },35 decorators: {36 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),37 optional: true38 }39 }40});41(0, _utils.default)("TSDeclareFunction", {42 aliases: ["Statement", "Declaration"],43 visitor: ["id", "typeParameters", "params", "returnType"],44 fields: Object.assign({}, _core.functionDeclarationCommon, tSFunctionTypeAnnotationCommon)45});46(0, _utils.default)("TSDeclareMethod", {47 visitor: ["decorators", "key", "typeParameters", "params", "returnType"],48 fields: Object.assign({}, _core.classMethodOrDeclareMethodCommon, tSFunctionTypeAnnotationCommon)49});50(0, _utils.default)("TSQualifiedName", {51 aliases: ["TSEntityName"],52 visitor: ["left", "right"],53 fields: {54 left: (0, _utils.validateType)("TSEntityName"),55 right: (0, _utils.validateType)("Identifier")56 }57});58const signatureDeclarationCommon = {59 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),60 parameters: (0, _utils.validateArrayOfType)(["Identifier", "RestElement"]),61 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation")62};63const callConstructSignatureDeclaration = {64 aliases: ["TSTypeElement"],65 visitor: ["typeParameters", "parameters", "typeAnnotation"],66 fields: signatureDeclarationCommon67};68(0, _utils.default)("TSCallSignatureDeclaration", callConstructSignatureDeclaration);69(0, _utils.default)("TSConstructSignatureDeclaration", callConstructSignatureDeclaration);70const namedTypeElementCommon = {71 key: (0, _utils.validateType)("Expression"),72 computed: (0, _utils.validate)(bool),73 optional: (0, _utils.validateOptional)(bool)74};75(0, _utils.default)("TSPropertySignature", {76 aliases: ["TSTypeElement"],77 visitor: ["key", "typeAnnotation", "initializer"],78 fields: Object.assign({}, namedTypeElementCommon, {79 readonly: (0, _utils.validateOptional)(bool),80 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"),81 initializer: (0, _utils.validateOptionalType)("Expression"),82 kind: {83 validate: (0, _utils.assertOneOf)("get", "set")84 }85 })86});87(0, _utils.default)("TSMethodSignature", {88 aliases: ["TSTypeElement"],89 visitor: ["key", "typeParameters", "parameters", "typeAnnotation"],90 fields: Object.assign({}, signatureDeclarationCommon, namedTypeElementCommon, {91 kind: {92 validate: (0, _utils.assertOneOf)("method", "get", "set")93 }94 })95});96(0, _utils.default)("TSIndexSignature", {97 aliases: ["TSTypeElement"],98 visitor: ["parameters", "typeAnnotation"],99 fields: {100 readonly: (0, _utils.validateOptional)(bool),101 static: (0, _utils.validateOptional)(bool),102 parameters: (0, _utils.validateArrayOfType)("Identifier"),103 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation")104 }105});106const tsKeywordTypes = ["TSAnyKeyword", "TSBooleanKeyword", "TSBigIntKeyword", "TSIntrinsicKeyword", "TSNeverKeyword", "TSNullKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSUndefinedKeyword", "TSUnknownKeyword", "TSVoidKeyword"];107for (const type of tsKeywordTypes) {108 (0, _utils.default)(type, {109 aliases: ["TSType", "TSBaseType"],110 visitor: [],111 fields: {}112 });113}114(0, _utils.default)("TSThisType", {115 aliases: ["TSType", "TSBaseType"],116 visitor: [],117 fields: {}118});119const fnOrCtrBase = {120 aliases: ["TSType"],121 visitor: ["typeParameters", "parameters", "typeAnnotation"]122};123(0, _utils.default)("TSFunctionType", Object.assign({}, fnOrCtrBase, {124 fields: signatureDeclarationCommon125}));126(0, _utils.default)("TSConstructorType", Object.assign({}, fnOrCtrBase, {127 fields: Object.assign({}, signatureDeclarationCommon, {128 abstract: (0, _utils.validateOptional)(bool)129 })130}));131(0, _utils.default)("TSTypeReference", {132 aliases: ["TSType"],133 visitor: ["typeName", "typeParameters"],134 fields: {135 typeName: (0, _utils.validateType)("TSEntityName"),136 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")137 }138});139(0, _utils.default)("TSTypePredicate", {140 aliases: ["TSType"],141 visitor: ["parameterName", "typeAnnotation"],142 builder: ["parameterName", "typeAnnotation", "asserts"],143 fields: {144 parameterName: (0, _utils.validateType)(["Identifier", "TSThisType"]),145 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"),146 asserts: (0, _utils.validateOptional)(bool)147 }148});149(0, _utils.default)("TSTypeQuery", {150 aliases: ["TSType"],151 visitor: ["exprName"],152 fields: {153 exprName: (0, _utils.validateType)(["TSEntityName", "TSImportType"])154 }155});156(0, _utils.default)("TSTypeLiteral", {157 aliases: ["TSType"],158 visitor: ["members"],159 fields: {160 members: (0, _utils.validateArrayOfType)("TSTypeElement")161 }162});163(0, _utils.default)("TSArrayType", {164 aliases: ["TSType"],165 visitor: ["elementType"],166 fields: {167 elementType: (0, _utils.validateType)("TSType")168 }169});170(0, _utils.default)("TSTupleType", {171 aliases: ["TSType"],172 visitor: ["elementTypes"],173 fields: {174 elementTypes: (0, _utils.validateArrayOfType)(["TSType", "TSNamedTupleMember"])175 }176});177(0, _utils.default)("TSOptionalType", {178 aliases: ["TSType"],179 visitor: ["typeAnnotation"],180 fields: {181 typeAnnotation: (0, _utils.validateType)("TSType")182 }183});184(0, _utils.default)("TSRestType", {185 aliases: ["TSType"],186 visitor: ["typeAnnotation"],187 fields: {188 typeAnnotation: (0, _utils.validateType)("TSType")189 }190});191(0, _utils.default)("TSNamedTupleMember", {192 visitor: ["label", "elementType"],193 builder: ["label", "elementType", "optional"],194 fields: {195 label: (0, _utils.validateType)("Identifier"),196 optional: {197 validate: bool,198 default: false199 },200 elementType: (0, _utils.validateType)("TSType")201 }202});203const unionOrIntersection = {204 aliases: ["TSType"],205 visitor: ["types"],206 fields: {207 types: (0, _utils.validateArrayOfType)("TSType")208 }209};210(0, _utils.default)("TSUnionType", unionOrIntersection);211(0, _utils.default)("TSIntersectionType", unionOrIntersection);212(0, _utils.default)("TSConditionalType", {213 aliases: ["TSType"],214 visitor: ["checkType", "extendsType", "trueType", "falseType"],215 fields: {216 checkType: (0, _utils.validateType)("TSType"),217 extendsType: (0, _utils.validateType)("TSType"),218 trueType: (0, _utils.validateType)("TSType"),219 falseType: (0, _utils.validateType)("TSType")220 }221});222(0, _utils.default)("TSInferType", {223 aliases: ["TSType"],224 visitor: ["typeParameter"],225 fields: {226 typeParameter: (0, _utils.validateType)("TSTypeParameter")227 }228});229(0, _utils.default)("TSParenthesizedType", {230 aliases: ["TSType"],231 visitor: ["typeAnnotation"],232 fields: {233 typeAnnotation: (0, _utils.validateType)("TSType")234 }235});236(0, _utils.default)("TSTypeOperator", {237 aliases: ["TSType"],238 visitor: ["typeAnnotation"],239 fields: {240 operator: (0, _utils.validate)((0, _utils.assertValueType)("string")),241 typeAnnotation: (0, _utils.validateType)("TSType")242 }243});244(0, _utils.default)("TSIndexedAccessType", {245 aliases: ["TSType"],246 visitor: ["objectType", "indexType"],247 fields: {248 objectType: (0, _utils.validateType)("TSType"),249 indexType: (0, _utils.validateType)("TSType")250 }251});252(0, _utils.default)("TSMappedType", {253 aliases: ["TSType"],254 visitor: ["typeParameter", "typeAnnotation", "nameType"],255 fields: {256 readonly: (0, _utils.validateOptional)(bool),257 typeParameter: (0, _utils.validateType)("TSTypeParameter"),258 optional: (0, _utils.validateOptional)(bool),259 typeAnnotation: (0, _utils.validateOptionalType)("TSType"),260 nameType: (0, _utils.validateOptionalType)("TSType")261 }262});263(0, _utils.default)("TSLiteralType", {264 aliases: ["TSType", "TSBaseType"],265 visitor: ["literal"],266 fields: {267 literal: {268 validate: function () {269 const unaryExpression = (0, _utils.assertNodeType)("NumericLiteral", "BigIntLiteral");270 const unaryOperator = (0, _utils.assertOneOf)("-");271 const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral");272 function validator(parent, key, node) {273 if ((0, _is.default)("UnaryExpression", node)) {274 unaryOperator(node, "operator", node.operator);275 unaryExpression(node, "argument", node.argument);276 } else {277 literal(parent, key, node);278 }279 }280 validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "UnaryExpression"];281 return validator;282 }()283 }284 }285});286(0, _utils.default)("TSExpressionWithTypeArguments", {287 aliases: ["TSType"],288 visitor: ["expression", "typeParameters"],289 fields: {290 expression: (0, _utils.validateType)("TSEntityName"),291 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")292 }293});294(0, _utils.default)("TSInterfaceDeclaration", {295 aliases: ["Statement", "Declaration"],296 visitor: ["id", "typeParameters", "extends", "body"],297 fields: {298 declare: (0, _utils.validateOptional)(bool),299 id: (0, _utils.validateType)("Identifier"),300 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),301 extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("TSExpressionWithTypeArguments")),302 body: (0, _utils.validateType)("TSInterfaceBody")303 }304});305(0, _utils.default)("TSInterfaceBody", {306 visitor: ["body"],307 fields: {308 body: (0, _utils.validateArrayOfType)("TSTypeElement")309 }310});311(0, _utils.default)("TSTypeAliasDeclaration", {312 aliases: ["Statement", "Declaration"],313 visitor: ["id", "typeParameters", "typeAnnotation"],314 fields: {315 declare: (0, _utils.validateOptional)(bool),316 id: (0, _utils.validateType)("Identifier"),317 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),318 typeAnnotation: (0, _utils.validateType)("TSType")319 }320});321(0, _utils.default)("TSAsExpression", {322 aliases: ["Expression"],323 visitor: ["expression", "typeAnnotation"],324 fields: {325 expression: (0, _utils.validateType)("Expression"),326 typeAnnotation: (0, _utils.validateType)("TSType")327 }328});329(0, _utils.default)("TSTypeAssertion", {330 aliases: ["Expression"],331 visitor: ["typeAnnotation", "expression"],332 fields: {333 typeAnnotation: (0, _utils.validateType)("TSType"),334 expression: (0, _utils.validateType)("Expression")335 }336});337(0, _utils.default)("TSEnumDeclaration", {338 aliases: ["Statement", "Declaration"],339 visitor: ["id", "members"],340 fields: {341 declare: (0, _utils.validateOptional)(bool),342 const: (0, _utils.validateOptional)(bool),343 id: (0, _utils.validateType)("Identifier"),344 members: (0, _utils.validateArrayOfType)("TSEnumMember"),345 initializer: (0, _utils.validateOptionalType)("Expression")346 }347});348(0, _utils.default)("TSEnumMember", {349 visitor: ["id", "initializer"],350 fields: {351 id: (0, _utils.validateType)(["Identifier", "StringLiteral"]),352 initializer: (0, _utils.validateOptionalType)("Expression")353 }354});355(0, _utils.default)("TSModuleDeclaration", {356 aliases: ["Statement", "Declaration"],357 visitor: ["id", "body"],358 fields: {359 declare: (0, _utils.validateOptional)(bool),360 global: (0, _utils.validateOptional)(bool),361 id: (0, _utils.validateType)(["Identifier", "StringLiteral"]),362 body: (0, _utils.validateType)(["TSModuleBlock", "TSModuleDeclaration"])363 }364});365(0, _utils.default)("TSModuleBlock", {366 aliases: ["Scopable", "Block", "BlockParent"],367 visitor: ["body"],368 fields: {369 body: (0, _utils.validateArrayOfType)("Statement")370 }371});372(0, _utils.default)("TSImportType", {373 aliases: ["TSType"],374 visitor: ["argument", "qualifier", "typeParameters"],375 fields: {376 argument: (0, _utils.validateType)("StringLiteral"),377 qualifier: (0, _utils.validateOptionalType)("TSEntityName"),378 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")379 }380});381(0, _utils.default)("TSImportEqualsDeclaration", {382 aliases: ["Statement"],383 visitor: ["id", "moduleReference"],384 fields: {385 isExport: (0, _utils.validate)(bool),386 id: (0, _utils.validateType)("Identifier"),387 moduleReference: (0, _utils.validateType)(["TSEntityName", "TSExternalModuleReference"]),388 importKind: {389 validate: (0, _utils.assertOneOf)("type", "value"),390 optional: true391 }392 }393});394(0, _utils.default)("TSExternalModuleReference", {395 visitor: ["expression"],396 fields: {397 expression: (0, _utils.validateType)("StringLiteral")398 }399});400(0, _utils.default)("TSNonNullExpression", {401 aliases: ["Expression"],402 visitor: ["expression"],403 fields: {404 expression: (0, _utils.validateType)("Expression")405 }406});407(0, _utils.default)("TSExportAssignment", {408 aliases: ["Statement"],409 visitor: ["expression"],410 fields: {411 expression: (0, _utils.validateType)("Expression")412 }413});414(0, _utils.default)("TSNamespaceExportDeclaration", {415 aliases: ["Statement"],416 visitor: ["id"],417 fields: {418 id: (0, _utils.validateType)("Identifier")419 }420});421(0, _utils.default)("TSTypeAnnotation", {422 visitor: ["typeAnnotation"],423 fields: {424 typeAnnotation: {425 validate: (0, _utils.assertNodeType)("TSType")426 }427 }428});429(0, _utils.default)("TSTypeParameterInstantiation", {430 visitor: ["params"],431 fields: {432 params: {433 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSType")))434 }435 }436});437(0, _utils.default)("TSTypeParameterDeclaration", {438 visitor: ["params"],439 fields: {440 params: {441 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSTypeParameter")))442 }443 }444});445(0, _utils.default)("TSTypeParameter", {446 builder: ["constraint", "default", "name"],447 visitor: ["constraint", "default"],448 fields: {449 name: {450 validate: (0, _utils.assertValueType)("string")451 },452 constraint: {453 validate: (0, _utils.assertNodeType)("TSType"),454 optional: true455 },456 default: {457 validate: (0, _utils.assertNodeType)("TSType"),458 optional: true459 }460 }...

Full Screen

Full Screen

validate.js

Source:validate.js Github

copy

Full Screen

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

Full Screen

Full Screen

creditcard.js

Source:creditcard.js Github

copy

Full Screen

1define(["doh", "../creditCard"], function(doh, validate){2doh.register("dojox.validate.tests.creditcard",3 [{4 name:"isValidLuhn",5 runTest: function(tests) {6 tests.t(validate.isValidLuhn('5105105105105100')); //test string input7 tests.t(validate.isValidLuhn('5105-1051 0510-5100')); //test string input with dashes and spaces (commonly used when entering card #'s)8 tests.t(validate.isValidLuhn(38520000023237)); //test numerical input as well9 tests.f(validate.isValidLuhn(3852000002323)); //testing failures10 tests.t(validate.isValidLuhn(18)); //length doesnt matter11 tests.f(validate.isValidLuhn(818181)); //short length failure12 }13 },14 {15 name:"isValidCvv",16 runTest: function(tests) {17 tests.t(validate.isValidCvv('123','mc')); //string is ok18 tests.f(validate.isValidCvv('5AA','ec')); //invalid characters are not ok19 tests.t(validate.isValidCvv(723,'mc')); //numbers are ok too20 tests.f(validate.isValidCvv(7234,'mc')); //too long21 tests.t(validate.isValidCvv(612,'ec'));22 tests.t(validate.isValidCvv(421,'vi'));23 tests.t(validate.isValidCvv(543,'di'));24 tests.t(validate.isValidCvv('1234','ax'));25 tests.t(validate.isValidCvv(4321,'ax'));26 tests.f(validate.isValidCvv(43215,'ax')); //too long27 tests.f(validate.isValidCvv(215,'ax')); //too short28 }29 },30 {31 name:"isValidCreditCard",32 runTest: function(tests) {33 //misc checks34 tests.t(validate.isValidCreditCard('5105105105105100','mc')); //test string input35 tests.t(validate.isValidCreditCard('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s)36 tests.t(validate.isValidCreditCard(5105105105105100,'mc')); //test numerical input as well37 tests.f(validate.isValidCreditCard('5105105105105100','vi')); //fails, wrong card type38 //Mastercard/Eurocard checks39 tests.t(validate.isValidCreditCard('5105105105105100','mc'));40 tests.t(validate.isValidCreditCard('5204105105105100','ec'));41 tests.t(validate.isValidCreditCard('5303105105105100','mc'));42 tests.t(validate.isValidCreditCard('5402105105105100','ec'));43 tests.t(validate.isValidCreditCard('5501105105105100','mc'));44 //Visa card checks45 tests.t(validate.isValidCreditCard('4111111111111111','vi'));46 tests.t(validate.isValidCreditCard('4111111111010','vi'));47 //American Express card checks48 tests.t(validate.isValidCreditCard('378 2822 4631 0005','ax'));49 tests.t(validate.isValidCreditCard('341-1111-1111-1111','ax'));50 //Diners Club/Carte Blanch card checks51 tests.t(validate.isValidCreditCard('36400000000000','dc'));52 tests.t(validate.isValidCreditCard('38520000023237','bl'));53 tests.t(validate.isValidCreditCard('30009009025904','dc'));54 tests.t(validate.isValidCreditCard('30108009025904','bl'));55 tests.t(validate.isValidCreditCard('30207009025904','dc'));56 tests.t(validate.isValidCreditCard('30306009025904','bl'));57 tests.t(validate.isValidCreditCard('30405009025904','dc'));58 tests.t(validate.isValidCreditCard('30504009025904','bl'));59 //Discover card checks60 tests.t(validate.isValidCreditCard('6011111111111117','di'));61 //JCB card checks62 tests.t(validate.isValidCreditCard('3530111333300000','jcb'));63 tests.t(validate.isValidCreditCard('213100000000001','jcb'));64 tests.t(validate.isValidCreditCard('180000000000002','jcb'));65 tests.f(validate.isValidCreditCard('1800000000000002','jcb')); //should fail, good checksum, good prefix, but wrong length'66 //Enroute card checks67 tests.t(validate.isValidCreditCard('201400000000000','er'));68 tests.t(validate.isValidCreditCard('214900000000000','er'));69 }70 },71 {72 name:"isValidCreditCardNumber",73 runTest: function(tests) {74 //misc checks75 tests.f(validate.isValidCreditCardNumber('a4111111111111', 'vi')); //fails, alphas are not allowed76 tests.t(validate.isValidCreditCardNumber('5105105105105100','mc')); //test string input77 tests.t(validate.isValidCreditCardNumber('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s)78 tests.t(validate.isValidCreditCardNumber(5105105105105100,'mc')); //test numerical input as well79 tests.f(validate.isValidCreditCardNumber('5105105105105100','vi')); //fails, wrong card type80 //Mastercard/Eurocard checks81 tests.is("mc|ec", validate.isValidCreditCardNumber('5100000000000000')); //should match 'mc|ec'82 tests.is("mc|ec", validate.isValidCreditCardNumber('5200000000000000')); //should match 'mc|ec'83 tests.is("mc|ec", validate.isValidCreditCardNumber('5300000000000000')); //should match 'mc|ec'84 tests.is("mc|ec", validate.isValidCreditCardNumber('5400000000000000')); //should match 'mc|ec'85 tests.is("mc|ec", validate.isValidCreditCardNumber('5500000000000000')); //should match 'mc|ec'86 tests.f(validate.isValidCreditCardNumber('55000000000000000')); //should fail, too long87 //Visa card checks88 tests.is("vi", validate.isValidCreditCardNumber('4111111111111111')); //should match 'vi'89 tests.is("vi", validate.isValidCreditCardNumber('4111111111010')); //should match 'vi'90 //American Express card checks91 tests.is("ax", validate.isValidCreditCardNumber('378 2822 4631 0005')); //should match 'ax'92 tests.is("ax", validate.isValidCreditCardNumber('341-1111-1111-1111')); //should match 'ax'93 //Diners Club/Carte Blanch card checks94 tests.is("dc|bl", validate.isValidCreditCardNumber('36400000000000')); //should match 'dc|bl'95 tests.is("dc|bl", validate.isValidCreditCardNumber('38520000023237')); //should match 'dc|bl'96 tests.is("dc|bl", validate.isValidCreditCardNumber('30009009025904')); //should match 'di|bl'97 tests.is("dc|bl", validate.isValidCreditCardNumber('30108009025904')); //should match 'di|bl'98 tests.is("dc|bl", validate.isValidCreditCardNumber('30207009025904')); //should match 'di|bl'99 tests.is("dc|bl", validate.isValidCreditCardNumber('30306009025904')); //should match 'di|bl'100 tests.is("dc|bl", validate.isValidCreditCardNumber('30405009025904')); //should match 'di|bl'101 tests.is("dc|bl", validate.isValidCreditCardNumber('30504009025904')); //should match 'di|bl'102 //Discover card checks103 tests.is("di", validate.isValidCreditCardNumber('6011111111111117')); //should match 'di'104 //JCB card checks105 tests.is("jcb", validate.isValidCreditCardNumber('3530111333300000')); //should match 'jcb'106 tests.is("jcb", validate.isValidCreditCardNumber('213100000000001')); //should match 'jcb'107 tests.is("jcb", validate.isValidCreditCardNumber('180000000000002')); //should match 'jcb'108 tests.f(validate.isValidCreditCardNumber('1800000000000002')); //should fail, good checksum, good prefix, but wrong length'109 //Enroute card checks110 tests.is("er", validate.isValidCreditCardNumber('201400000000000')); //should match 'er'111 tests.is("er", validate.isValidCreditCardNumber('214900000000000')); //should match 'er'112 }113 }114]);...

Full Screen

Full Screen

formnovalidate-attribute.js

Source:formnovalidate-attribute.js Github

copy

Full Screen

1description("This test performs some simple check on the formnovalidate attribute.");2var i = document.createElement("input");3var b = document.createElement("button");4shouldBe("i.hasAttribute('formNoValidate')", "false");5shouldBe("i.getAttribute('formNoValidate')", "null");6shouldBe("i.formNoValidate", "false");7shouldBe("b.hasAttribute('formNoValidate')", "false");8shouldBe("b.getAttribute('formNoValidate')", "null");9shouldBe("b.formNoValidate", "false");10i.formNoValidate = true;11b.formNoValidate = true;12shouldBe("i.hasAttribute('formNoValidate')", "true");13shouldBe("i.getAttribute('formNoValidate')", "''");14shouldBe("i.formNoValidate", "true");15shouldBe("b.hasAttribute('formNoValidate')", "true");16shouldBe("b.getAttribute('formNoValidate')", "''");17shouldBe("b.formNoValidate", "true");18var i2 = document.createElement("input");19i2.formNoValidate = i.formNoValidate;20i.formNoValidate = false;21b.formNoValidate = false;22shouldBe("i.hasAttribute('formNoValidate')", "false");23shouldBe("i.getAttribute('formNoValidate')", "null");24shouldBe("i.formNoValidate", "false");25shouldBe("b.hasAttribute('formNoValidate')", "false");26shouldBe("b.getAttribute('formNoValidate')", "null");27shouldBe("b.formNoValidate", "false");28i2.formNoValidate = false;29shouldBe("i2.formNoValidate", "false");30i2.formNoValidate = "something";31shouldBe("i2.hasAttribute('formNoValidate')", "true");32shouldBe("i2.getAttribute('formNoValidate')", "''");33shouldBe("i2.formNoValidate", "true");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { validate } = require('taiko');2const { openBrowser, goto, closeBrowser } = require('taiko');3(async () => {4 try {5 await openBrowser();6 await goto("google.com");7 await validate("Google", "Google");8 await closeBrowser();9 } catch (error) {10 console.error(error);11 } finally {12 }13})();14### validateFields(fields, values)15const { validateFields } = require('taiko');16const { openBrowser, goto, closeBrowser } = require('taiko');17(async () => {18 try {19 await openBrowser();20 await goto("google.com");21 await validateFields(["Google"], ["Google"]);22 await closeBrowser();23 } catch (error) {24 console.error(error);25 } finally {26 }27})();28### validateFields(fields, values, options)29const { validateFields } = require('taiko');30const { openBrowser, goto, closeBrowser } = require('taiko');31(async () => {32 try {33 await openBrowser();34 await goto("google.com");35 await validateFields(["Google"], ["Google"], { waitForEvents: ["load", "domcontentloaded", "networkidle"] });36 await closeBrowser();37 } catch (error) {38 console.error(error);39 } finally {40 }41})();42### validateLocation(location)43const { validateLocation } = require('taiko');44const { openBrowser, goto, closeBrowser } = require('taiko');45(async () => {46 try {47 await openBrowser();48 await goto("google.com");49 await validateLocation("google.com

Full Screen

Using AI Code Generation

copy

Full Screen

1const { validate } = require('taiko');2const assert = require('assert');3const { openBrowser, goto, closeBrowser } = require('taiko');4(async () => {5 try {6 await openBrowser();7 await validate(async () => {8 const title = await title();9 assert.ok(title.includes('Google'));10 });11 } catch (e) {12 console.error(e);13 } finally {14 await closeBrowser();15 }16})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { validate } = require('taiko');2const { validate } = require('taiko');3const { validate } = require('taiko');4const { validate } = require('taiko');5const { validate } = require('taiko');6const { validate } = require('taiko');7const { validate } = require('taiko');8const { validate } = require('taiko');9const { validate } = require('taiko');10const { validate } = require('taiko');11const { validate } = require('taiko');12const { validate } = require('taiko');13const { validate } = require('taiko');14const { validate } = require('taiko');15const { validate } = require('taiko');16const { validate } = require('taiko');17const { validate } = require('taiko');18const { validate } = require('taiko');19const { validate } = require('taiko');20const { validate } = require('taiko');21const { validate } = require('taiko');22const { validate } = require('taiko');23const { validate } = require('taiko');24const { validate } = require('taiko');25const { validate } = require('taiko');

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require("assert");2const { openBrowser, goto, closeBrowser, textBox, into, write, button, click, text, validate } = require('taiko');3(async () => {4 try {5 await openBrowser();6 await write("tomsmith", into(textBox("Username")));7 await write("SuperSecretPassword!", into(textBox("Password")));8 await click(button("Login"));9 await validate("You logged into a secure area!", text("You logged into a secure area!"));10 } catch (error) {11 console.error(error);12 } finally {13 await closeBrowser();14 }15})();16We welcome contributions to Taiko. See [Contributing](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { validate } = require('taiko');2const { validate } = require('taiko');3validate(condition, message, options);4const { validate } = require('taiko');5const { openBrowser, goto, closeBrowser } = require('taiko');6(async () => {7 try {8 await openBrowser();9 await goto("google.com");10 await validate(async () => {11 return await text("Google Search").exists();12 }, "Google Search button does not exist");13 } catch (e) {14 console.error(e);15 } finally {16 await closeBrowser();17 }18})();19const { validate } = require('taiko');20const { openBrowser, goto, closeBrowser } = require('taiko');21(async () => {22 try {23 await openBrowser();24 await goto("google.com");25 await validate(async () => {26 return await text("Google Search").exists();27 }, "Google Search button does not exist", {28 });29 } catch (e) {30 console.error(e);31 } finally {32 await closeBrowser();33 }34})();35const { validate } = require('taiko');36const { openBrowser, goto, closeBrowser } = require('taiko');37(async () => {38 try {39 await openBrowser();40 await goto("google.com");41 await validate(async () => {42 return await text("Google Search").exists();43 }, "Google Search button does not exist", {

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const taiko = require('taiko');3const { openBrowser, goto, closeBrowser, button, textBox, link, text, image, write, press, click, $, waitFor, toRightOf, below, toLeftOf, evaluate, highlight, focus, hover, $x, $xpath, toLeftOf, toRightOf, above, below, near, intercept, setConfig, openTab, reload, attach, emulate, clear, scrollTo, scrollRight, scrollLeft, scrollUp, scrollDown, scrollDownTo, scrollUpTo, scrollRightTo, scrollLeftTo, scrollIntoView, doubleClick, rightClick, tap, dragAndDrop, dragAndDropFiles, select, deselect, deselectAll, accept, dismiss, waitForNavigation, waitForElement, waitForText, waitForTitle, waitForURL, waitForRequest, waitForResponse, waitForFunction, waitForLoadEvent, waitForPaintingStops, waitForNetworkIdle, to, into, intoAll, withText, withLink, withPlaceholder, withValue, withId, withClass, withName, withDescendant, withLabel, withAttribute, withExactText, withI18nText, withCSS, withXPath, toRightOf, toLeftOf, above, below, near, within, dropDown, radioButton, checkBox, listItem, tableCell, tableRow, fileField, colorField, dateField, dateTimeLocalField, emailField, monthField, numberField, passwordField, rangeField, searchField, telField, textField, timeField, urlField, weekField, image } = require('taiko');4const { createHtml, removeFile, openBrowserArgs, resetConfig } = require('./test-util');5const test_name = 'Validate';6step("Validate <element> <property> <value>", async (element, property, value) => {7 assert.ok(await validate(element, property, value));8});9step("Validate <element> <property> <value> <message>", async (element, property, value, message) => {10 assert.ok(await validate(element, property, value, message));11});12step("Validate <element> <property> <value> <message> <options>", async (element, property, value, message, options) => {13 assert.ok(await validate(element, property, value, message, options));14});15step("Validate <element> <property>

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run taiko automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful