jquery.inputmask.phone.extensions.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Input Mask plugin extensions
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - 2014 Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. Version: 0.0.0
  7. Phone extension.
  8. When using this extension make sure you specify the correct url to get the masks
  9. $(selector).inputmask("phone", {
  10. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  11. onKeyValidation: function () { //show some metadata in the console
  12. console.log($(this).inputmask("getmetadata")["cd"]);
  13. }
  14. });
  15. */
  16. (function ($) {
  17. $.extend($.inputmask.defaults.aliases, {
  18. 'phone': {
  19. url: "phone-codes/phone-codes.js",
  20. maskInit: "+pp(pp)pppppppp",
  21. mask: function (opts) {
  22. opts.definitions = {
  23. 'p': {
  24. validator: function () { return false; },
  25. cardinality: 1
  26. },
  27. '#': {
  28. validator: "[0-9]",
  29. cardinality: 1
  30. }
  31. };
  32. var maskList = [];
  33. $.ajax({
  34. url: opts.url,
  35. async: false,
  36. dataType: 'json',
  37. success: function (response) {
  38. maskList = response;
  39. }
  40. });
  41. maskList.splice(0, 0, opts.maskInit);
  42. maskList.sort(function (a, b) { return a.length - b.length; });
  43. return maskList;
  44. },
  45. nojumps: true,
  46. nojumpsThreshold: 1
  47. },
  48. 'phonebe': {
  49. alias: "phone",
  50. url: "phone-codes/phone-be.js",
  51. maskInit: "+32(pp)pppppppp",
  52. nojumpsThreshold: 4
  53. }
  54. });
  55. return $.fn.inputmask;
  56. })(jQuery);