jquery.inputmask.phone.extensions.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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")["name_en"]);
  13. }
  14. });
  15. */
  16. (function ($) {
  17. $.extend($.inputmask.defaults.aliases, {
  18. 'phone': {
  19. url: "phone-codes/phone-codes.json",
  20. mask: function (opts) {
  21. opts.definitions = {
  22. 'p': {
  23. validator: function () { return false; },
  24. cardinality: 1
  25. },
  26. '#': {
  27. validator: "[0-9]",
  28. cardinality: 1
  29. }
  30. };
  31. var maskList = [];
  32. $.ajax({
  33. url: opts.url,
  34. async: false,
  35. dataType: 'json',
  36. success: function (response) {
  37. maskList = response;
  38. }
  39. });
  40. maskList.splice(0, 0, "+p(ppp)ppp-pppp");
  41. return maskList;
  42. }
  43. }
  44. });
  45. })(jQuery);