base64.js 761 B

123456789101112131415161718192021
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.base64 = {
  3. /**
  4. * Return true if the input value is a base 64 encoded string.
  5. *
  6. * @param {BootstrapValidator} validator The validator plugin instance
  7. * @param {jQuery} $field Field element
  8. * @param {Object} options Can consist of the following keys:
  9. * - message: The invalid message
  10. * @returns {Boolean}
  11. */
  12. validate: function(validator, $field, options) {
  13. var value = $field.val();
  14. if (value == '') {
  15. return true;
  16. }
  17. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  18. }
  19. };
  20. }(window.jQuery));