grid.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. (function($) {
  2. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  3. 'default': 'Please enter a valid GRId number'
  4. });
  5. $.fn.bootstrapValidator.validators.grid = {
  6. /**
  7. * Validate GRId (Global Release Identifier)
  8. * Examples:
  9. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  10. * - Invalid: A1-2425G-ABC1234002-Q
  11. *
  12. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  13. * @param {BootstrapValidator} validator The validator plugin instance
  14. * @param {jQuery} $field Field element
  15. * @param {Object} options Can consist of the following keys:
  16. * - message: The invalid message
  17. * @returns {Boolean}
  18. */
  19. validate: function(validator, $field, options) {
  20. var value = $field.val();
  21. if (value === '') {
  22. return true;
  23. }
  24. value = value.toUpperCase();
  25. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  26. return false;
  27. }
  28. value = value.replace(/\s/g, '').replace(/-/g, '');
  29. if ('GRID:' === value.substr(0, 5)) {
  30. value = value.substr(5);
  31. }
  32. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  33. }
  34. };
  35. }(window.jQuery));