jquery.inputmask.phone.extensions.js 1.4 KB

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