|
383 | 383 | * @returns {Boolean} |
384 | 384 | */ |
385 | 385 | validate: function(validator, $field, options) { |
386 | | - var value = parseFloat($field.val()); |
| 386 | + var value = $field.val(); |
| 387 | + if (value == '') { |
| 388 | + return true; |
| 389 | + } |
| 390 | + |
| 391 | + value = parseFloat(value); |
387 | 392 | return (options.inclusive === true) |
388 | 393 | ? (value > options.min && value < options.max) |
389 | 394 | : (value >= options.min && value <= options.max); |
|
408 | 413 | */ |
409 | 414 | validate: function(validator, $field, options) { |
410 | 415 | var value = $field.val(); |
| 416 | + if (value == '') { |
| 417 | + return true; |
| 418 | + } |
| 419 | + |
411 | 420 | if (options.callback && 'function' == typeof options.callback) { |
412 | 421 | return options.callback.call(this, value, this); |
413 | 422 | } |
|
429 | 438 | */ |
430 | 439 | validate: function(validator, $field, options) { |
431 | 440 | var value = $field.val(); |
| 441 | + if (value == '') { |
| 442 | + return true; |
| 443 | + } |
432 | 444 |
|
433 | 445 | // Accept only digits, dashes or spaces |
434 | 446 | if (/[^0-9-\s]+/.test(value)) { |
|
469 | 481 | * @returns {Boolean} |
470 | 482 | */ |
471 | 483 | validate: function(validator, $field, options) { |
472 | | - var value = $field.val(), |
473 | | - $compareWith = validator.getFieldElement(options.field); |
| 484 | + var value = $field.val(); |
| 485 | + if (value == '') { |
| 486 | + return true; |
| 487 | + } |
| 488 | + |
| 489 | + var $compareWith = validator.getFieldElement(options.field); |
474 | 490 | if ($compareWith && value != $compareWith.val()) { |
475 | 491 | validator.removeError($compareWith); |
476 | 492 | return true; |
|
491 | 507 | * @returns {Boolean} |
492 | 508 | */ |
493 | 509 | validate: function(validator, $field, options) { |
494 | | - return /^\d+$/.test($field.val()); |
| 510 | + var value = $field.val(); |
| 511 | + if (value == '') { |
| 512 | + return true; |
| 513 | + } |
| 514 | + |
| 515 | + return /^\d+$/.test(value); |
495 | 516 | } |
496 | 517 | } |
497 | 518 | }(window.jQuery)); |
|
506 | 527 | * @returns {Boolean} |
507 | 528 | */ |
508 | 529 | validate: function(validator, $field, options) { |
509 | | - var value = $field.val(), |
510 | | - // Email address regular expression |
511 | | - // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript |
512 | | - emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| 530 | + var value = $field.val(); |
| 531 | + if (value == '') { |
| 532 | + return true; |
| 533 | + } |
| 534 | + |
| 535 | + // Email address regular expression |
| 536 | + // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript |
| 537 | + var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
513 | 538 | return emailRegExp.test(value); |
514 | 539 | } |
515 | 540 | } |
|
528 | 553 | * @returns {Boolean} |
529 | 554 | */ |
530 | 555 | validate: function(validator, $field, options) { |
531 | | - var value = parseFloat($field.val()); |
| 556 | + var value = $field.val(); |
| 557 | + if (value == '') { |
| 558 | + return true; |
| 559 | + } |
| 560 | + value = parseFloat(value); |
532 | 561 | return (options.inclusive === true) ? (value > options.value) : (value >= options.value); |
533 | 562 | } |
534 | 563 | } |
|
546 | 575 | */ |
547 | 576 | validate: function(validator, $field, options) { |
548 | 577 | var value = $field.val(); |
| 578 | + if (value == '') { |
| 579 | + return true; |
| 580 | + } |
549 | 581 | return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value); |
550 | 582 | } |
551 | 583 | }; |
|
562 | 594 | * @returns {Boolean} |
563 | 595 | */ |
564 | 596 | validate: function(validator, $field, options) { |
565 | | - var value = $field.val(), |
566 | | - $compareWith = validator.getFieldElement(options.field); |
| 597 | + var value = $field.val(); |
| 598 | + if (value == '') { |
| 599 | + return true; |
| 600 | + } |
| 601 | + |
| 602 | + var $compareWith = validator.getFieldElement(options.field); |
567 | 603 | if ($compareWith && value == $compareWith.val()) { |
568 | 604 | validator.removeError($compareWith); |
569 | 605 | return true; |
|
587 | 623 | * @returns {Boolean} |
588 | 624 | */ |
589 | 625 | validate: function(validator, $field, options) { |
590 | | - var value = parseFloat($field.val()); |
| 626 | + var value = $field.val(); |
| 627 | + if (value == '') { |
| 628 | + return true; |
| 629 | + } |
| 630 | + value = parseFloat(value); |
591 | 631 | return (options.inclusive === true) ? (value < options.value) : (value <= options.value); |
592 | 632 | } |
593 | 633 | }; |
|
621 | 661 | */ |
622 | 662 | validate: function(validator, $field, options) { |
623 | 663 | var value = $field.val(); |
| 664 | + if (value == '') { |
| 665 | + return true; |
| 666 | + } |
| 667 | + |
624 | 668 | return options.regexp.test(value); |
625 | 669 | } |
626 | 670 | }; |
|
639 | 683 | * <fieldName>: <fieldValue> |
640 | 684 | * } |
641 | 685 | * - message: The invalid message |
642 | | - * @returns {String} |
| 686 | + * @returns {Boolean|String} |
643 | 687 | */ |
644 | 688 | validate: function(validator, $field, options) { |
645 | | - var value = $field.val(), name = $field.attr('name'), data = options.data; |
| 689 | + var value = $field.val(); |
| 690 | + if (value == '') { |
| 691 | + return true; |
| 692 | + } |
| 693 | + |
| 694 | + var name = $field.attr('name'), data = options.data; |
646 | 695 | if (data == null) { |
647 | 696 | data = {}; |
648 | 697 | } |
|
676 | 725 | * @returns {Boolean} |
677 | 726 | */ |
678 | 727 | validate: function(validator, $field, options) { |
679 | | - var value = $.trim($field.val()), length = value.length; |
| 728 | + var value = $field.val(); |
| 729 | + if (value == '') { |
| 730 | + return true; |
| 731 | + } |
| 732 | + |
| 733 | + var length = $.trim(value).length; |
680 | 734 | if ((options.min && length < options.min) || (options.max && length > options.max)) { |
681 | 735 | return false; |
682 | 736 | } |
|
696 | 750 | * @returns {Boolean} |
697 | 751 | */ |
698 | 752 | validate: function(validator, $field, options) { |
| 753 | + var value = $field.val(); |
| 754 | + if (value == '') { |
| 755 | + return true; |
| 756 | + } |
| 757 | + |
699 | 758 | // Credit to https://gist.github.com/dperini/729294 |
700 | 759 | // |
701 | 760 | // Regular Expression for URL validation |
|
769 | 828 | "(?:/[^\\s]*)?" + |
770 | 829 | "$", "i" |
771 | 830 | ); |
772 | | - return urlExp.test($field.val()); |
| 831 | + return urlExp.test(value); |
773 | 832 | } |
774 | 833 | }; |
775 | 834 | }(window.jQuery)); |
|
785 | 844 | */ |
786 | 845 | validate: function(validateInstance, $field, options) { |
787 | 846 | var value = $field.val(); |
| 847 | + if (value == '') { |
| 848 | + return true; |
| 849 | + } |
788 | 850 | return /^\d{5}([\-]\d{4})?$/.test(value); |
789 | 851 | } |
790 | 852 | }; |
|
0 commit comments