1/*! jQuery Validation Plugin - v1.10.0 - 9/7/2012 2* https://github.com/jzaefferer/jquery-validation 3* Copyright (c) 2012 Jörn Zaefferer; Licensed MIT, GPL */ 4 5(function($) { 6 $.extend($.fn, { 7 // http://docs.jquery.com/Plugins/Validation/validate 8 validate: function( options ) { 9 // if nothing is selected, return nothing; can't chain anyway 10 if (!this.length) { 11 if (options && options.debug && window.console) { 12 console.warn( "nothing selected, can't validate, returning nothing" ); 13 } 14 return; 15 } 16 // check if a validator for this form was already created 17 var validator = $.data(this[0], 'validator'); 18 if ( validator ) { 19 return validator; 20 } 21 // Add novalidate tag if HTML5. 22 this.attr('novalidate', 'novalidate'); 23 validator = new $.validator( options, this[0] ); 24 $.data(this[0], 'validator', validator); 25 if ( validator.settings.onsubmit ) { 26 this.validateDelegate( ":submit", "click", function(ev) { 27 if ( validator.settings.submitHandler ) { 28 validator.submitButton = ev.target; 29 } 30 // allow suppressing validation by adding a cancel class to the submit button 31 if ( $(ev.target).hasClass('cancel') ) { 32 validator.cancelSubmit = true; 33 } 34 }); 35 // validate the form on submit 36 this.submit( function( event ) { 37 if ( validator.settings.debug ) { 38 // prevent form submit to be able to see console output 39 event.preventDefault(); 40 } 41 function handle() { 42 var hidden; 43 if ( validator.settings.submitHandler ) { 44 if (validator.submitButton) { 45 // insert a hidden input as a replacement for the missing submit button 46 hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm); 47 } 48 validator.settings.submitHandler.call( validator, validator.currentForm, event ); 49 if (validator.submitButton) { 50 // and clean up afterwards; thanks to no-block-scope, hidden can be referenced 51 hidden.remove(); 52 } 53 return false; 54 } 55 return true; 56 } 57 // prevent submit for invalid forms or custom submit handlers 58 if ( validator.cancelSubmit ) { 59 validator.cancelSubmit = false; 60 return handle(); 61 } 62 if ( validator.form() ) { 63 if ( validator.pendingRequest ) { 64 validator.formSubmitted = true; 65 return false; 66 } 67 return handle(); 68 } else { 69 sig.alert("Dados obrigatórios não preenchidos.\n Favor verificar.","Erro",{ 70 Ok: function(){ 71 $(this).dialog("close"); 72 } 73 }); 74 validator.focusInvalid(); 75 return false; 76 } 77 }); 78 } 79 return validator; 80 }, 81 // http://docs.jquery.com/Plugins/Validation/valid 82 valid: function() { 83 if ( $(this[0]).is('form')) { 84 return this.validate().form(); 85 } else { 86 var valid = true;
87 var validator = $(this[0].form).validate(); 88 this.each(function() { 89 valid &= validator.element(this); 90 }); 91 return valid; 92 } 93 }, 94 // attributes: space seperated list of attributes to retrieve and remove 95 removeAttrs: function(attributes) { 96 var result = {}, 97 $element = this; 98 $.each(attributes.split(/\s/), function(index, value) { 99 result[value] = $element.attr(value); 100 $element.removeAttr(value); 101 }); 102 return result; 103 }, 104 // http://docs.jquery.com/Plugins/Validation/rules 105 rules: function(command, argument) { 106 var element = this[0]; 107 if (command) { 108 var settings = $.data(element.form, 'validator').settings; 109 var staticRules = settings.rules; 110 var existingRules = $.validator.staticRules(element); 111 switch(command) { 112 case "add": 113 $.extend(existingRules, $.validator.normalizeRule(argument)); 114 staticRules[element.name] = existingRules; 115 if (argument.messages) { 116 settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages ); 117 } 118 break; 119 case "remove": 120 if (!argument) { 121 delete staticRules[element.name]; 122 return existingRules; 123 } 124 var filtered = {}; 125 $.each(argument.split(/\s/), function(index, method) { 126 filtered[method] = existingRules[method]; 127 delete existingRules[method]; 128 }); 129 return filtered; 130 } 131 } 132 var data = $.validator.normalizeRules( 133 $.extend( 134 {}, 135 $.validator.metadataRules(element), 136 $.validator.classRules(element), 137 $.validator.attributeRules(element), 138 $.validator.staticRules(element) 139 ), element); 140 // make sure required is at front 141 if (data.required) { 142 var param = data.required; 143 delete data.required; 144 data = $.extend({ 145 required: param 146 }, data); 147 } 148 return data; 149 } 150 }); 151 // Custom selectors 152 $.extend($.expr[":"], { 153 // http://docs.jquery.com/Plugins/Validation/blank 154 blank: function(a) { 155 return !$.trim("" + a.value); 156 }, 157 // http://docs.jquery.com/Plugins/Validation/filled 158 filled: function(a) { 159 return !!$.trim("" + a.value); 160 }, 161 // http://docs.jquery.com/Plugins/Validation/unchecked 162 unchecked: function(a) { 163 return !a.checked; 164 } 165 }); 166 // constructor for validator 167 $.validator = function( options, form ) { 168 this.settings = $.extend( true, {}, $.validator.defaults, options ); 169 this.currentForm = form; 170 this.init(); 171 }; 172 $.validator.format = function(source, params) { 173 if ( arguments.length === 1 ) { 174 return function() { 175 var args = $.makeArray(arguments); 176 args.unshift(source); 177 return $.validator.format.apply( this, args ); 178 }; 179 } 180 if ( arguments.length > 2 && params.constructor !== Array ) { 181 params = $.makeArray(arguments).slice(1); 182 } 183 if ( params.constructor !== Array ) { 184 params = [ params ]; 185 } 186 $.each(params, function(i, n) { 187 source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); 188 }); 189 return source; 190 }; 191 192 $.extend($.validator, { 193 defaults: { 194 messages: {}, 195 groups: {}, 196 rules: {}, 197 errorClass: "error", 198 validClass: "valid", 199 errorElement: "label", 200 focusInvalid: true, 201 errorContainer: $( [] ), 202 errorLabelContainer: $( [] ), 203 onsubmit: true, 204 ignore: ":hidden", 205 ignoreTitle: false, 206 onfocusin: function(element, event) { 207 this.lastActive = element; 208 // hide error label and remove error class on focus if enabled 209 if ( this.settings.focusCleanup && !this.blockFocusCleanup ) { 210 if ( this.settings.unhighlight ) { 211 this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.val
211idClass ); 212 } 213 this.addWrapper(this.errorsFor(element)).hide(); 214 } 215 }, 216 onfocusout: function(element, event) { 217 if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { 218 this.element(element); 219 } 220 }, 221 onkeyup: function(element, event) { 222 if ( event.which === 9 && this.elementValue(element) === '' ) { 223 return; 224 } else if ( element.name in this.submitted || element === this.lastActive ) { 225 this.element(element); 226 } 227 }, 228 onclick: function(element, event) { 229 // click on selects, radiobuttons and checkboxes 230 if ( element.name in this.submitted ) { 231 this.element(element); 232 } 233 // or option elements, check parent select in that case 234 else if (element.parentNode.name in this.submitted) { 235 this.element(element.parentNode); 236 } 237 }, 238 highlight: function(element, errorClass, validClass) { 239 if (element.type === 'radio') { 240 this.findByName(element.name).addClass(errorClass).removeClass(validClass); 241 } else { 242 $(element).addClass(errorClass).removeClass(validClass); 243 } 244 }, 245 unhighlight: function(element, errorClass, validClass) { 246 if (element.type === 'radio') { 247 this.findByName(element.name).removeClass(errorClass).addClass(validClass); 248 } else { 249 $(element).removeClass(errorClass).addClass(validClass); 250 } 251 } 252 }, 253 // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults 254 setDefaults: function(settings) { 255 $.extend( $.validator.defaults, settings ); 256 }, 257 messages: { 258 required: "This field is required.", 259 remote: "Please fix this field.", 260 email: "Please enter a valid email address.", 261 url: "Please enter a valid URL.", 262 date: "Please enter a valid date.", 263 dateISO: "Please enter a valid date (ISO).", 264 number: "Please enter a valid number.", 265 numberDE: "Bitte geben Sie eine Nummer ein.", 266 numberMaior: "Maior que zero.", 267 contaTotalizadora: "Não é permitido lançar em contas Totalizadoras.", 268 digits: "Please enter only digits.", 269 creditcard: "Please enter a valid credit card number.", 270 equalTo: "Please enter the same value again.", 271 maxlength: $.validator.format("Please enter no more than {0} characters."), 272 minlength: $.validator.format("Please enter at least {0} characters."), 273 rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."), 274 range: $.validator.format("Please enter a value between {0} and {1}."), 275 max: $.validator.format("Please enter a value less than or equal to {0}."), 276 min: $.validator.format("Please enter a value greater than or equal to {0}.") 277 }, 278 autoCreateRanges: false, 279 prototype: { 280 init: function() { 281 this.labelContainer = $(this.settings.errorLabelContainer); 282 this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm); 283 this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer ); 284 this.submitted = {}; 285 this.valueCache = {}; 286 this.pendingRequest = 0; 287 this.pending = {}; 288 this.invalid = {}; 289 this.reset(); 290 291 var groups = (this.groups = {}); 292 $.each(this.settings.groups, function(key, value) { 293 $.each(value.split(/\s/), function(index, name) { 294 groups[name] = key; 295 }); 296 }); 297 var rules = this.settings.rules; 298 $.each(rules, function(key, value) { 299 rules[key] = $.validator.normalizeRule(value); 300 }); 301 function delegate(event) {
302 var validator = $.data(this[0].form, "validator"), 303 eventType = "on" + event.type.replace(/^validate/, ""); 304 if (validator.settings[eventType]) { 305 validator.settings[eventType].call(validator, this[0], event); 306 } 307 } 308 $(this.currentForm) 309 .validateDelegate(":text, [type='password'], [type='file'], select, textarea, " + 310 "[type='number'], [type='search'] ,[type='tel'], [type='url'], " + 311 "[type='email'], [type='datetime'], [type='date'], [type='month'], " + 312 "[type='week'], [type='time'], [type='datetime-local'], " + 313 "[type='range'], [type='color'] ", 314 "focusin focusout keyup", delegate) 315 .validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate); 316 317 if (this.settings.invalidHandler) { 318 $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler); 319 } 320 }, 321 // http://docs.jquery.com/Plugins/Validation/Validator/form 322 form: function() { 323 this.checkForm(); 324 $.extend(this.submitted, this.errorMap); 325 this.invalid = $.extend({}, this.errorMap); 326 if (!this.valid()) { 327 $(this.currentForm).triggerHandler("invalid-form", [this]); 328 } 329 this.showErrors(); 330 return this.valid(); 331 }, 332 checkForm: function() { 333 this.prepareForm(); 334 for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) { 335 this.check( elements[i] ); 336 } 337 return this.valid(); 338 }, 339 // http://docs.jquery.com/Plugins/Validation/Validator/element 340 element: function( element ) { 341 element = this.validationTargetFor( this.clean( element ) ); 342 this.lastElement = element; 343 this.prepareElement( element ); 344 this.currentElements = $(element); 345 var result = this.check( element ) !== false; 346 if (result) { 347 delete this.invalid[element.name]; 348 } else { 349 this.invalid[element.name] = true; 350 } 351 if ( !this.numberOfInvalids() ) { 352 // Hide error containers on last error 353 this.toHide = this.toHide.add( this.containers ); 354 } 355 this.showErrors(); 356 return result; 357 }, 358 // http://docs.jquery.com/Plugins/Validation/Validator/showErrors 359 showErrors: function(errors) { 360 if(errors) { 361 // add items to error list and map 362 $.extend( this.errorMap, errors ); 363 this.errorList = []; 364 for ( var name in errors ) { 365 this.errorList.push({ 366 message: errors[name], 367 element: this.findByName(name)[0] 368 }); 369 } 370 // remove items from success list 371 this.successList = $.grep( this.successList, function(element) { 372 return !(element.name in errors); 373 }); 374 } 375 if (this.settings.showErrors) { 376 this.settings.showErrors.call( this, this.errorMap, this.errorList ); 377 } else { 378 this.defaultShowErrors(); 379 } 380 }, 381 // http://docs.jquery.com/Plugins/Validation/Validator/resetForm 382 resetForm: function() { 383 if ( $.fn.resetForm ) { 384 $( this.currentForm ).resetForm(); 385 } 386 this.submitted = {}; 387 this.lastElement = null; 388 this.prepareForm(); 389 this.hideErrors(); 390 this.elements().removeClass( this.settings.errorClass ).removeData( "previousValue" ); 391 }, 392 numberOfInvalids: function() { 393 return this.objectLength(this.invalid); 394 }, 395 objectLength: function( obj ) { 396 var count = 0; 397 for ( var i in obj ) { 398 count++; 399 } 400 return count; 401 }, 402 hideErrors: function() { 403 this.addWrapper( this.toHide ).hide(); 404 }, 405 valid: function() { 406 return this.size() === 0; 407 }, 408 size: function() { 409 return this.errorList.length; 410 }, 411 focusInvalid: function() { 412 if( this.settings.focusInvalid ) { 413 try { 414 $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []) 415 .filter(":visible") 416 .focus() 417 // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find 418 .trigger("focusin"); 419 } catch(e) {
420 // ignore IE throwing errors when focusing hidden elements 421 } 422 } 423 }, 424 findLastActive: function() { 425 var lastActive = this.lastActive; 426 return lastActive && $.grep(this.errorList, function(n) { 427 return n.element.name === lastActive.name; 428 }).length === 1 && lastActive; 429 }, 430 elements: function() { 431 var validator = this, 432 rulesCache = {}; 433 434 // select all valid inputs inside the form (no submit or reset buttons) 435 return $(this.currentForm) 436 .find("input, select, textarea") 437 .not(":submit, :reset, :image, [disabled]") 438 .not( this.settings.ignore ) 439 //Em algum momento foi colocado essa conf. más estava atrapalhando outras validações. 440 //.not( this.settings.ignore += ':not(.chzn-done)') 441 .filter(function() { 442 if ( !this.name && validator.settings.debug && window.console ) { 443 console.error( "%o has no name assigned", this); 444 } 445 // select only the first element for each name, and only those with rules specified 446 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) { 447 return false; 448 } 449 rulesCache[this.name] = true; 450 return true; 451 }); 452 }, 453 clean: function( selector ) { 454 return $( selector )[0]; 455 }, 456 errors: function() { 457 var errorClass = this.settings.errorClass.replace(' ', '.'); 458 return $( this.settings.errorElement + "." + errorClass, this.errorContext ); 459 }, 460 reset: function() { 461 this.successList = []; 462 this.errorList = []; 463 this.errorMap = {}; 464 this.toShow = $([]); 465 this.toHide = $([]); 466 this.currentElements = $([]); 467 }, 468 prepareForm: function() { 469 this.reset(); 470 this.toHide = this.errors().add( this.containers ); 471 }, 472 prepareElement: function( element ) { 473 this.reset(); 474 this.toHide = this.errorsFor(element); 475 }, 476 elementValue: function( element ) { 477 var type = $(element).attr('type'), 478 val = $(element).val(); 479 if ( type === 'radio' || type === 'checkbox' ) { 480 return $('input[name="' + $(element).attr('name') + '"]:checked').val(); 481 } 482 if ( typeof val === 'string' ) { 483 return val.replace(/\r/g, ""); 484 } 485 return val; 486 }, 487 check: function( element ) { 488 element = this.validationTargetFor( this.clean( element ) ); 489 var rules = $(element).rules(); 490 var dependencyMismatch = false; 491 var val = this.elementValue(element); 492 var result; 493 for (var method in rules ) { 494 var rule = { 495 method: method, 496 parameters: rules[method] 497 }; 498 try { 499 result = $.validator.methods[method].call( this, val, element, rule.parameters ); 500 // if a method indicates that the field is optional and therefore valid, 501 // don't mark it as valid when there are no other rules 502 if ( result === "dependency-mismatch" ) { 503 dependencyMismatch = true; 504 continue; 505 } 506 dependencyMismatch = false; 507 if ( result === "pending" ) { 508 this.toHide = this.toHide.not( this.errorsFor(element) ); 509 return; 510 } 511 if( !result ) { 512 this.formatAndAdd( element, rule ); 513 return false;
514 } 515 } catch(e) { 516 if ( this.settings.debug && window.console ) { 517 console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e); 518 } 519 throw e; 520 } 521 } 522 if (dependencyMismatch) { 523 return; 524 } 525 if ( this.objectLength(rules) ) { 526 this.successList.push(element); 527 } 528 return true; 529 }, 530 // return the custom message for the given element and validation method 531 // specified in the element's "messages" metadata 532 customMetaMessage: function(element, method) { 533 if (!$.metadata) { 534 return; 535 } 536 var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata(); 537 return meta && meta.messages && meta.messages[method]; 538 }, 539 // return the custom message for the given element and validation method 540 // specified in the element's HTML5 data attribute 541 customDataMessage: function(element, method) { 542 return $(element).data('msg-' + method.toLowerCase()) || (element.attributes && $(element).attr('data-msg-' + method.toLowerCase())); 543 }, 544 // return the custom message for the given element name and validation method 545 customMessage: function( name, method ) { 546 var m = this.settings.messages[name]; 547 return m && (m.constructor === String ? m : m[method]); 548 }, 549 // return the first defined argument, allowing empty strings 550 findDefined: function() { 551 for(var i = 0; i < arguments.length; i++) { 552 if (arguments[i] !== undefined) { 553 return arguments[i]; 554 } 555 } 556 return undefined; 557 }, 558 defaultMessage: function( element, method) { 559 return this.findDefined( 560 this.customMessage( element.name, method ), 561 this.customDataMessage( element, method ), 562 this.customMetaMessage( element, method ), 563 // title is never undefined, so handle empty string as undefined 564 !this.settings.ignoreTitle && element.title || undefined, 565 $.validator.messages[method], 566 "<strong>Warning: No message defined for " + element.name + "</strong>" 567 ); 568 }, 569 formatAndAdd: function( element, rule ) { 570 var message = this.defaultMessage( element, rule.method ), 571 theregex = /\$?\{(\d+)\}/g; 572 if ( typeof message === "function" ) { 573 message = message.call(this, rule.parameters, element); 574 } else if (theregex.test(message)) { 575 message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters); 576 } 577 this.errorList.push({ 578 message: message, 579 element: element 580 }); 581 this.errorMap[element.name] = message; 582 this.submitted[element.name] = message; 583 }, 584 addWrapper: function(toToggle) { 585 if ( this.settings.wrapper ) { 586 toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); 587 } 588 return toToggle; 589 }, 590 defaultShowErrors: function() { 591 var i, elements; 592 for ( i = 0; this.errorList[i]; i++ ) { 593 var error = this.errorList[i]; 594 if ( this.settings.highlight ) { 595 this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.val
595idClass ); 596 } 597 this.showLabel( error.element, error.message ); 598 } 599 if( this.errorList.length ) { 600 this.toShow = this.toShow.add( this.containers ); 601 } 602 if (this.settings.success) { 603 for ( i = 0; this.successList[i]; i++ ) { 604 this.showLabel( this.successList[i] ); 605 } 606 } 607 if (this.settings.unhighlight) { 608 for ( i = 0, elements = this.validElements(); elements[i]; i++ ) { 609 this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass ); 610 } 611 } 612 this.toHide = this.toHide.not( this.toShow ); 613 this.hideErrors(); 614 this.addWrapper( this.toShow ).show(); 615 }, 616 validElements: function() { 617 return this.currentElements.not(this.invalidElements()); 618 }, 619 invalidElements: function() { 620 return $(this.errorList).map(function() { 621 return this.element; 622 }); 623 }, 624 showLabel: function(element, message) { 625 var label = this.errorsFor( element ); 626 if ( label.length ) { 627 // refresh error/success class 628 label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass ); 629 // check if we have a generated label, replace the message then 630 if ( label.attr("generated") ) { 631 label.html(message); 632 } 633 } else { 634 // create label 635 label = $("<" + this.settings.errorElement + "/>") 636 .attr({ 637 "for": this.idOrName(element), 638 generated: true 639 }) 640 .addClass(this.settings.errorClass) 641 .html(message || ""); 642 if ( this.settings.wrapper ) { 643 // make sure the element is visible, even in IE 644 // actually showing the wrapped element is handled elsewhere 645 label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent(); 646 } 647 if ( !this.labelContainer.append(label).length ) { 648 if ( this.settings.errorPlacement ) { 649 this.settings.errorPlacement(label, $(element) ); 650 } else { 651 label.insertAfter(element); 652 } 653 } 654 } 655 if ( !message && this.settings.success ) { 656 label.text(""); 657 if ( typeof this.settings.success === "string" ) { 658 label.addClass( this.settings.success ); 659 } else { 660 this.settings.success( label, element ); 661 } 662 } 663 this.toShow = this.toShow.add(label); 664 }, 665 errorsFor: function(element) { 666 var name = this.idOrName(element); 667 return this.errors().filter(function() { 668 return $(this).attr('for') === name; 669 }); 670 }, 671 idOrName: function(element) { 672 return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); 673 }, 674 validationTargetFor: function(element) { 675 // if radio/checkbox, validate first element in group instead 676 if (this.checkable(element)) { 677 element = this.findByName( element.name ).not(this.settings.ignore)[0]; 678 } 679 return element; 680 }, 681 checkable: function( element ) { 682 return (/radio|checkbox/i).test(element.type); 683 }, 684 findByName: function( name ) { 685 return $(this.currentForm).find('[name="' + name + '"]'); 686 }, 687 getLength: function(value, element) { 688 switch( element.nodeName.toLowerCase() ) { 689 case 'select': 690 return $("option:selected", element).length; 691 case 'input': 692 if( this.checkable( element) ) { 693 return this.findByName(element.name).filter(':checked').length; 694 } 695 } 696 return value.length; 697 }, 698 depend: function(param, element) { 699 return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true; 700 }, 701 dependTypes: { 702 "boolean": function(param, element) { 703 return param; 704 }, 705 "string": function(param, element) { 706 return !!$(param, element.form).length; 707 }, 708 "function": function(param, element) { 709 return param(element); 710 } 711 }, 712 optional: function(element) { 713 var val = this.elementValue(element); 714 return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch"; 715 }, 716 startRequest: function(element) { 717 if (!this.pending[element.name]) { 718 this.pendingRequest++; 719 this.pending[element.name] = true; 720 } 721 }, 722 stopRequest: function(element, valid) { 723 this.pendingRequest--; 724 // sometimes synchronization fails, make sure pendingRequest is never < 0 725 if (this.pendingRequest < 0) { 726 this.pendingRequest = 0; 727 } 728 delete this.pending[element.name]; 729 if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) { 730 $(this.currentForm).submit(); 731 this.formSubmitted = false;
732 } else if (!valid && this.pendingRequest === 0 && this.formSubmitted) { 733 $(this.currentForm).triggerHandler("invalid-form", [this]); 734 this.formSubmitted = false; 735 } 736 }, 737 previousValue: function(element) { 738 return $.data(element, "previousValue") || $.data(element, "previousValue", { 739 old: null, 740 valid: true, 741 message: this.defaultMessage( element, "remote" ) 742 }); 743 } 744 745 }, 746 classRuleSettings: { 747 required: { 748 required: true 749 }, 750 email: { 751 email: true 752 }, 753 url: { 754 url: true 755 }, 756 date: { 757 date: true 758 }, 759 dateISO: { 760 dateISO: true 761 }, 762 dateBR: { 763 dateBR: true 764 }, 765 data: { 766 data: true 767 }, 768 number: { 769 number: true 770 }, 771 numberDE: { 772 numberDE: true 773 }, 774 numberMaior: { 775 numberMaior: true 776 }, 777 contaTotalizadora: { 778 contaTotalizadora: true 779 }, 780 digits: { 781 digits: true 782 }, 783 creditcard: { 784 creditcard: true 785 } 786 }, 787 addClassRules: function(className, rules) { 788 if ( className.constructor === String ) { 789 this.classRuleSettings[className] = rules; 790 } else { 791 $.extend(this.classRuleSettings, className); 792 } 793 }, 794 classRules: function(element) { 795 var rules = {}; 796 var classes = $(element).attr('class'); 797 if ( classes ) { 798 $.each(classes.split(' '), function() { 799 if (this in $.validator.classRuleSettings) { 800 $.extend(rules, $.validator.classRuleSettings[this]); 801 } 802 }); 803 } 804 return rules; 805 }, 806 attributeRules: function(element) { 807 var rules = {}; 808 var $element = $(element); 809 for (var method in $.validator.methods) { 810 var value; 811 812 // support for <input required> in both html5 and older browsers 813 if (method === 'required') { 814 value = $element.get(0).getAttribute(method); 815 // Some browsers return an empty string for the required attribute 816 // and non-HTML5 browsers might have required="" markup 817 if (value === "") { 818 value = true; 819 } 820 // force non-HTML5 browsers to return bool 821 value = !!value; 822 } else { 823 value = $element.attr(method); 824 } 825 if (value) { 826 rules[method] = value; 827 } else if ($element[0].getAttribute("type") === method) { 828 rules[method] = true; 829 } 830 } 831 // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs 832 if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { 833 delete rules.maxlength; 834 } 835 return rules; 836 }, 837 metadataRules: function(element) { 838 if (!$.metadata) { 839 return {}; 840 } 841 var meta = $.data(element.form, 'validator').settings.meta; 842 return meta ? 843 $(element).metadata()[meta] : 844 $(element).metadata(); 845 }, 846 staticRules: function(element) { 847 var rules = {}; 848 var validator = $.data(element.form, 'validator'); 849 if (validator.settings.rules) { 850 rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {}; 851 } 852 return rules; 853 }, 854 normalizeRules: function(rules, element) { 855 // handle dependency check 856 $.each(rules, function(prop, val) { 857 // ignore rule when param is explicitly false, eg. required:false 858 if (val === false) { 859 delete rules[prop]; 860 return; 861 } 862 if (val.param || val.depends) { 863 var keepRule = true; 864 switch (typeof val.depends) { 865 case "string": 866 keepRule = !!$(val.depends, element.form).length; 867 break; 868 case "function": 869 keepRule = val.depends.call(element, element); 870 break; 871 } 872 if (keepRule) { 873 rules[prop] = val.param !== undefined ? val.param : true; 874 } else { 875 delete rules[prop]; 876 } 877 } 878 }); 879 // evaluate parameters 880 $.each(rules, function(rule, parameter) { 881 rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter; 882 }); 883 // clean number parameters 884 $.each(['minlength', 'maxlength', 'min', 'max'], function() { 885 if (rules[this]) { 886 rules[this] = Number(rules[this]); 887 } 888 }); 889 $.each(['rangelength', 'range'], function() { 890 if (rules[this]) { 891 rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; 892 } 893 }); 894 if ($.validator.autoCreateRanges) { 895 // auto-create ranges 896 if (rules.min && rules.max) { 897 rules.range = [rules.min, rules.max]; 898 delete rules.min; 899 delete rules.max; 900 } 901 if (rules.minlength && rules.maxlength) { 902 rules.rangelength = [rules.minlength, rules.maxlength]; 903 delete rules.minlength; 904 delete rules.maxlength; 905 } 906 } 907 // To support custom messages in metadata ignore rule methods titled "messages" 908 if (rules.messages) { 909 delete rules.messages; 910 } 911 return rules; 912 },
913 // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} 914 normalizeRule: function(data) { 915 if( typeof data === "string" ) { 916 var transformed = {}; 917 $.each(data.split(/\s/), function() { 918 transformed[this] = true; 919 }); 920 data = transformed; 921 } 922 return data; 923 }, 924 // http://docs.jquery.com/Plugins/Validation/Validator/addMethod 925 addMethod: function(name, method, message) { 926 $.validator.methods[name] = method; 927 $.validator.messages[name] = message !== undefined ? message : $.validator.messages[name]; 928 if (method.length < 3) { 929 $.validator.addClassRules(name, $.validator.normalizeRule(name)); 930 } 931 }, 932 methods: { 933 // http://docs.jquery.com/Plugins/Validation/Methods/required 934 required: function(value, element, param) { 935 // check if dependency is met 936 if ( !this.depend(param, element) ) { 937 return "dependency-mismatch"; 938 } 939 if ( element.nodeName.toLowerCase() === "select" ) { 940 // could be an array for select-multiple or a string, both are fine this way 941 var val = $(element).val(); 942 return val && val.length > 0; 943 } 944 if ( this.checkable(element) ) { 945 return this.getLength(value, element) > 0; 946 } 947 return $.trim(value).length > 0; 948 }, 949 // http://docs.jquery.com/Plugins/Validation/Methods/remote 950 remote: function(value, element, param) { 951 if ( this.optional(element) ) { 952 return "dependency-mismatch"; 953 } 954 var previous = this.previousValue(element); 955 if (!this.settings.messages[element.name] ) { 956 this.settings.messages[element.name] = {}; 957 } 958 previous.originalMessage = this.settings.messages[element.name].remote; 959 this.settings.messages[element.name].remote = previous.message; 960 param = typeof param === "string" && { 961 url:param 962 } || param; 963 if ( this.pending[element.name] ) { 964 return "pending"; 965 } 966 if ( previous.old === value ) { 967 return previous.valid; 968 } 969 previous.old = value; 970 var validator = this; 971 this.startRequest(element); 972 var data = {}; 973 data[element.name] = value; 974 $.ajax($.extend(true, { 975 url: param, 976 mode: "abort", 977 port: "validate" + element.name, 978 dataType: "json", 979 data: data, 980 success: function(response) { 981 validator.settings.messages[element.name].remote = previous.originalMessage; 982 var valid = response === true || response === "true"; 983 if ( valid ) { 984 var submitted = validator.formSubmitted; 985 validator.prepareElement(element); 986 validator.formSubmitted = submitted; 987 validator.successList.push(element); 988 delete validator.invalid[element.name]; 989 validator.showErrors(); 990 } else { 991 var errors = {}; 992 var message = response || validator.defaultMessage( element, "remote" ); 993 errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message; 994 validator.invalid[element.name] = true; 995 validator.showErrors(errors); 996 } 997 previous.valid = valid; 998 validator.stopRequest(element, valid); 999 } 1000 }, param)); 1001 return "pending"; 1002 }, 1003 // http://docs.jquery.com/Plugins/Validation/Methods/minlength 1004 minlength: function(value, element, param) { 1005 var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); 1006 return this.optional(element) || length >= param; 1007 }, 1008 // http://docs.jquery.com/Plugins/Validation/Methods/maxlength 1009 maxlength: function(value, element, param) { 1010 var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); 1011 return this.optional(element) || length <= param; 1012 }, 1013 // http://docs.jquery.com/Plugins/Validation/Methods/rangelength 1014 rangelength: function(value, element, param) { 1015 var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); 1016 return this.optional(element) || ( length >= param[0] && length <= param[1] ); 1017 }, 1018 // http://docs.jquery.com/Plugins/Validation/Methods/min 1019 min: function( value, element, param ) { 1020 return this.optional(element) || value >= param; 1021 }, 1022 // http://docs.jquery.com/Plugins/Validation/Methods/max 1023 max: function( value, element, param ) { 1024 return this.optional(element) || value <= param; 1025 }, 1026 notamax: function( value, element, param ) { 1027 value = parseFloat(value.replace(/[.]/g,'').replace(',','.')); 1028 //sig.notificar(value); 1029 return this.optional(element) || value <= param; 1030 }, 1031 // http://docs.jquery.com/Plugins/Validation/Methods/range 1032 range: function( value, element, param ) { 1033 return this.optional(element) || ( value >= param[0] && value <= param[1] ); 1034 }, 1035 // http://docs.jquery.com/Plugins/Validation/Methods/email 1036 email: function(value, element) { 1037 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ 1038 return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value); 1039 }, 1040 // http://docs.jquery.com/Plugins/Validation/Methods/url 1041 url: function(value, element) { 1042 // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ 1043 return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); 1044 }, 1045 // http://docs.jquery.com/Plugins/Validation/Methods/date 1046 date: function(value, element) { 1047 return this.optional(element) || !/Invalid|NaN/.test(new Date(value)); 1048 }, 1049 // http://docs.jquery.com/Plugins/Validation/Methods/dateISO 1050 dateISO: function(value, element) { 1051 return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value); 1052 }, 1053 // http://docs.jquery.com/Plugins/Validation/Methods/dateISO 1054 dateBR: function(value, element) { 1055 return this.optional(element) || /^\d{1,2}[\/-]\d{1,2}[\/-]\d{4}$/.test(value); 1056 }, 1057 // http://docs.jquery.com/Plugins/Validation/Methods/dateISO 1058 data: function(value, element) { 1059 return this.optional(element) || /^\d{1,2}[\/-]\d{1,2}[\/-]\d{4}$/.test(value); 1060 }, 1061 // http://docs.jquery.com/Plugins/Validation/Methods/number 1062 number: function(value, element) { 1063 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value); 1064 }, 1065 // http://docs.jquery.com/Plugins/Validation/Methods/numberDE 1066 numberDE: function(value, element) { 1067 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value); 1068 }, 1069 // http://docs.jquery.com/Plugins/Validation/Methods/numberDE 1070 numberMaior: function(value, element) { 1071 return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value); 1072 }, 1073 /*contaTotalizadora: function(value, element) { 1074 return this.optional(element) || /\(Totalizadora\)$/i.test(value); 1075 },*/ 1076 // http://docs.jquery.com/Plugins/Validation/Methods/digits 1077 digits: function(value, element) { 1078 return this.optional(element) || /^\d+$/.test(value); 1079 }, 1080 // http://docs.jquery.com/Plugins/Validation/Methods/creditcard 1081 // based on http://en.wikipedia.org/wiki/Luhn 1082 creditcard: function(value, element) { 1083 if ( this.optional(element) ) { 1084 return "dependency-mismatch"; 1085 } 1086 // accept only spaces, digits and dashes 1087 if (/[^0-9 \-]+/.test(value)) { 1088 return false;
1089 } 1090 var nCheck = 0, 1091 nDigit = 0, 1092 bEven = false; 1093 1094 value = value.replace(/\D/g, ""); 1095 1096 for (var n = value.length - 1; n >= 0; n--) { 1097 var cDigit = value.charAt(n); 1098 nDigit = parseInt(cDigit, 10); 1099 if (bEven) { 1100 if ((nDigit *= 2) > 9) { 1101 nDigit -= 9; 1102 } 1103 } 1104 nCheck += nDigit; 1105 bEven = !bEven; 1106 } 1107 return (nCheck % 10) === 0; 1108 }, 1109 // http://docs.jquery.com/Plugins/Validation/Methods/equalTo 1110 equalTo: function(value, element, param) { 1111 // bind to the blur event of the target in order to revalidate whenever the target field is updated 1112 // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead 1113 var target = $(param); 1114 if (this.settings.onfocusout) { 1115 target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() { 1116 $(element).valid(); 1117 }); 1118 } 1119 return value === target.val(); 1120 }, 1121 valorNumericoExato: function( value, element, param ) { 1122 return this.optional(element) || parseFloat(value) == param; 1123 } 1124 } 1125 }); 1126 // deprecated, use $.validator.format instead 1127 $.format = $.validator.format; 1128 1129}(jQuery)); 1130// ajax mode: abort 1131// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); 1132// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() 1133(function($) { 1134 var pendingRequests = {}; 1135 // Use a prefilter if available (1.5+) 1136 if ( $.ajaxPrefilter ) { 1137 $.ajaxPrefilter(function(settings, _, xhr) { 1138 var port = settings.port; 1139 if (settings.mode === "abort") { 1140 if ( pendingRequests[port] ) { 1141 pendingRequests[port].abort(); 1142 } 1143 pendingRequests[port] = xhr; 1144 } 1145 }); 1146 } else { 1147 // Proxy ajax 1148 var ajax = $.ajax; 1149 $.ajax = function(settings) { 1150 var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode, 1151 port = ( "port" in settings ? settings : $.ajaxSettings ).port; 1152 if (mode === "abort") { 1153 if ( pendingRequests[port] ) { 1154 pendingRequests[port].abort(); 1155 } 1156 return (pendingRequests[port] = ajax.apply(this, arguments)); 1157 } 1158 return ajax.apply(this, arguments); 1159 }; 1160 } 1161}(jQuery)); 1162// provides cross-browser focusin and focusout events 1163// IE has native support, in other browsers, use event caputuring (neither bubbles) 1164// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation 1165// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target 1166(function($) { 1167 // only implement if not provided by jQuery core (since 1.4) 1168 // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs 1169 if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) { 1170 $.each({ 1171 focus: 'focusin', 1172 blur: 'focusout' 1173 }, function( original, fix ){ 1174 $.event.special[fix] = { 1175 setup:function() { 1176 this.addEventListener( original, handler, true ); 1177 }, 1178 teardown:function() { 1179 this.removeEventListener( original, handler, true ); 1180 }, 1181 handler: function(e) { 1182 var args = arguments; 1183 args[0] = $.event.fix(e); 1184 args[0].type = fix; 1185 return $.event.handle.apply(this, args); 1186 } 1187 }; 1188 function handler(e) { 1189 e = $.event.fix(e); 1190 e.type = fix; 1191 return $.event.handle.call(this, e); 1192 } 1193 }); 1194 } 1195 $.extend($.fn, { 1196 validateDelegate: function(delegate, type, handler) { 1197 return this.bind(type, function(event) { 1198 var target = $(event.target); 1199 if (target.is(delegate)) { 1200 return handler.apply(target, arguments); 1201 } 1202 }); 1203 } 1204 }); 1205}(jQuery)); 1206 1207jQuery.extend(jQuery.validator.messages, { 1208 required: "Campo obrigatório.", 1209 remote: "Por favor, corrija este campo.", 1210 email: "Por favor, forneça um e-mail válido.", 1211 url: "Por favor, forneça uma URL válida.", 1212 date: "Por favor, forneça uma data válida.", 1213 dateISO: "Por favor, forneça uma data válida (ISO).", 1214 dateBR: "Por favor, forneça uma data válida.", 1215 data: "Por favor, forneça uma data válida.", 1216 number: "Por favor, forneça um número válida.", 1217 numberDE: "Bitte geben Sie eine Nummer ein.", 1218 numberMaior: "Maior que zero.", 1219 contaTotalizadora: "Não é permitido lançar em contas Totalizadoras.", 1220 senhaForte: "Sua Senha deve atingir um nÃvel de segurança médio.", 1221 digits: "Por favor, forneça somente dígitos.", 1222 creditcard: "Por favor, forneç
1222a um cartão de crédito válido.", 1223 equalTo: "Por favor, forneça o mesmo valor novamente.", 1224 valorNumericoExato: "O valor deve ser exatamente igual a {0}.", 1225 accept: "Por favor, forneça um valor com uma extensão válida.", 1226 maxlength: jQuery.validator.format("Por favor, forneça não mais que {0} caracteres."), 1227 minlength: jQuery.validator.format("Por favor, forneça ao menos {0} caracteres."), 1228 rangelength: jQuery.validator.format("Por favor, forneça um valor entre {0} e {1} caracteres de comprimento."), 1229 range: jQuery.validator.format("Por favor, forneça um valor entre {0} e {1}."), 1230 max: jQuery.validator.format("Por favor, forneça um valor menor ou igual a {0}."), 1231 notamax: jQuery.validator.format("A nota não pode exceder {0}."), 1232 min: jQuery.validator.format("Por favor, forneça um valor maior ou igual a {0}.") 1233}); 1234 1235jQuery.validator.addMethod("cnpj", function(cnpj, element) { 1236 cnpj = jQuery.trim(cnpj);// retira espaços em branco 1237 // DEIXA APENAS OS NÃMEROS 1238 cnpj = cnpj.replace('/',''); 1239 cnpj = cnpj.replace('.',''); 1240 cnpj = cnpj.replace('.',''); 1241 cnpj = cnpj.replace('-',''); 1242 1243 var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais; 1244 digitos_iguais = 1; 1245 1246 if (cnpj.length < 14 && cnpj.length < 15){ 1247 return false; 1248 } 1249 for (i = 0; i < cnpj.length - 1; i++){ 1250 if (cnpj.charAt(i) != cnpj.charAt(i + 1)){ 1251 digitos_iguais = 0; 1252 break; 1253 } 1254 } 1255 1256 if (!digitos_iguais){ 1257 tamanho = cnpj.length - 2; 1258 numeros = cnpj.substring(0,tamanho); 1259 digitos = cnpj.substring(tamanho); 1260 soma = 0; 1261 pos = tamanho - 7; 1262 1263 for (i = tamanho; i >= 1; i--){ 1264 soma += numeros.charAt(tamanho - i) * pos--; 1265 if (pos < 2){ 1266 pos = 9; 1267 } 1268 } 1269 resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 1270 if (resultado != digitos.charAt(0)){ 1271 return false; 1272 } 1273 tamanho = tamanho + 1; 1274 numeros = cnpj.substring(0,tamanho); 1275 soma = 0; 1276 pos = tamanho - 7; 1277 for (i = tamanho; i >= 1; i--){ 1278 soma += numeros.charAt(tamanho - i) * pos--; 1279 if (pos < 2){ 1280 pos = 9; 1281 } 1282 } 1283 resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; 1284 if (resultado != digitos.charAt(1)){ 1285 return false; 1286 } 1287 return true; 1288 }else{ 1289 return false; 1290 } 1291}, "Informe um CNPJ válido."); 1292jQuery.validator.addMethod("cpf", function(value, element) { 1293 value = jQuery.trim(value); 1294 value = value.replace('.',''); 1295 value = value.replace('.',''); 1296 cpf = value.replace('-',''); 1297 while(cpf.length < 11) cpf = "0"+ cpf; 1298 var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/; 1299 var a = []; 1300 var b = new Number; 1301 var c = 11; 1302 for (i=0; i<11; i++){ 1303 a[i] = cpf.charAt(i); 1304 if (i < 9) b += (a[i] * --c); 1305 } 1306 if ((x = b % 11) < 2) { 1307 a[9] = 0 1308 } else { 1309 a[9] = 11-x 1310 } 1311 b = 0; 1312 c = 11; 1313 for (y=0; y<10; y++) b += (a[y] * c--); 1314 if ((x = b % 11) < 2) { 1315 a[10] = 0; 1316 } else { 1317 a[10] = 11-x; 1318 } 1319 if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]) || cpf.match(expReg)) return false; 1320 return true; 1321}, "Informe um CPF válido."); // Mensagem padrão 1322 1323jQuery.validator.addMethod("dateBR", function(value, element) { 1324 //contando chars 1325 if(value.length!=10) return false; 1326 // verificando data 1327 var data = value; 1328 var dia = data.substr(0,2); 1329 var barra1 = data.substr(2,1); 1330 var mes = data.substr(3,2); 1331 var barra2 = data.substr(5,1); 1332 var ano = data.substr(6,4); 1333 if(data.length!=10||barra1!="/"||barra2!="/"||isNaN(dia)||isNaN(mes)||isNaN(ano)||dia>31||mes>12)return false; 1334 if((mes==4||mes==6||mes==9||mes==11) && dia==31)return false; 1335 if(mes==2 && (dia>29||(dia==29 && ano%4!=0)))return false; 1336 if(ano < 1900)return false; 1337 return true; 1338}, "Informe uma data válida"); // Mensagem padrão 1339jQuery.validator.addMethod("data", function(value, element) { 1340 //contando chars 1341 if(value.length ==0) return true; 1342 if(value.length!=10) return false;
1343 // verificando data 1344 var data = value; 1345 var dia = data.substr(0,2); 1346 var barra1 = data.substr(2,1); 1347 var mes = data.substr(3,2); 1348 var barra2 = data.substr(5,1); 1349 var ano = data.substr(6,4); 1350 if(data.length!=10||barra1!="/"||barra2!="/"||isNaN(dia)||isNaN(mes)||isNaN(ano)||dia>31||mes>12)return false; 1351 if((mes==4||mes==6||mes==9||mes==11) && dia==31)return false; 1352 if(mes==2 && (dia>29||(dia==29 && ano%4!=0)))return false; 1353 if(ano < 1900)return false; 1354 return true; 1355}, "Informe uma data válida"); // Mensagem padrão 1356jQuery.validator.addMethod("numberMaior", function(value, element) { 1357 value = value.replace('.',''); 1358 if(value.replace(',','.') > 0) return true; 1359}, "Maior que zero"); // Mensagem padrão 1360jQuery.validator.addMethod("contaTotalizadora", function(value, element) { 1361 textSelect = $("#"+$(element).attr('id')+" option:selected").text(); 1362 1363 if (!/\(Totalizadora\)$/i.test(textSelect)){ 1364 return true; 1365 } 1366}, "Não é permitido lançar em contas Totalizadoras."); // Mensagem padrão 1367jQuery.validator.addMethod("senhaForte", function(value, element) { 1368 textSenha = $("#"+$(element).attr('id')).val(); 1369 arrayNivel = ['Muito Fraca','Fraca','Medio','Forte','Muito Forte']; 1370 nivelAtingido = 0; 1371 $.each(arrayNivel, function(key, value) { 1372 if (value == textSenha){ 1373 nivelAtingido = key; 1374 } 1375 }); 1376 1377 nivelDesejado = 2;//nÃvel Medio 1378 if (nivelAtingido >= nivelDesejado){ 1379 return true; 1380 } else { 1381 return false; 1382 } 1383}, "Sua Senha deve atingir um nÃvel de segurança médio."); // Mensagem padrão
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.