siren.js 647 B

123456789101112131415161718192021222324
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.siren = {
  3. /**
  4. * Check if a string is a siren number
  5. *
  6. * @param {BootstrapValidator} validator The validator plugin instance
  7. * @param {jQuery} $field Field element
  8. * @param {Object} options Consist of key:
  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. if (!/^\d{9}$/.test(value)) {
  18. return false;
  19. }
  20. return $.fn.bootstrapValidator.helpers.luhn(value);
  21. }
  22. };
  23. }(window.jQuery));