jquery.inputmask.regex.extensions.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. Input Mask plugin extensions
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - 2013 Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. Version: 0.0.0
  7. Regex extensions on the jquery.inputmask base
  8. Allows for using regular expressions as a mask
  9. */
  10. (function ($) {
  11. $.extend($.inputmask.defaults.aliases, { // $(selector).inputmask("Regex", { regex: "a regex expression"}
  12. 'Regex': {
  13. mask: "r",
  14. greedy: false,
  15. repeat: 10, //needs to be computed
  16. regex: null,
  17. regexSplit: null,
  18. definitions: {
  19. 'r': {
  20. validator: function (chrs, buffer, pos, strict, opts) {
  21. function analyseRegex() {
  22. //implement me
  23. }
  24. if(opts.regexSplit == null){
  25. opts.regexSplit = analyseRegex();
  26. }
  27. var cbuffer = buffer.splice(pos + 1, 0, chrs),
  28. regexPart, isValid = false;
  29. for(var i = 0; i < regexSplit.length; i++) {
  30. regexPart += opts.regexSplit[i];
  31. var exp = new RegExp(regexPart);
  32. isValid = exp.test(cbuffer);
  33. if(isValid) break;
  34. }
  35. return isValid;
  36. }
  37. }
  38. }
  39. }
  40. });
  41. })(jQuery);