Best Python code snippet using yandex-tank
validation.test.js
Source:validation.test.js
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 });...
test-validation.js
Source:test-validation.js
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));...
flow.js
Source:flow.js
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 }...
script.validate.js
Source:script.validate.js
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);
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!