inputmask.extensions.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. Input Mask plugin extensions
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. Version: 0.0.0-dev
  7. Optional extensions on the jquery.inputmask base
  8. */
  9. (function (factory) {
  10. if (typeof define === "function" && define.amd) {
  11. define(["./dependencyLibs/inputmask.dependencyLib", "./inputmask"], factory);
  12. } else if (typeof exports === "object") {
  13. module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask"));
  14. } else {
  15. factory(window.dependencyLib || jQuery, window.Inputmask);
  16. }
  17. }
  18. (function ($, Inputmask) {
  19. //extra definitions
  20. Inputmask.extendDefinitions({
  21. "A": {
  22. validator: "[A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
  23. cardinality: 1,
  24. casing: "upper" //auto uppercasing
  25. },
  26. "&": { //alfanumeric uppercasing
  27. validator: "[0-9A-Za-z\u0410-\u044F\u0401\u0451\u00C0-\u00FF\u00B5]",
  28. cardinality: 1,
  29. casing: "upper"
  30. },
  31. "#": { //hexadecimal
  32. validator: "[0-9A-Fa-f]",
  33. cardinality: 1,
  34. casing: "upper"
  35. }
  36. });
  37. Inputmask.extendAliases({
  38. "url": {
  39. definitions: {
  40. "i": {
  41. validator: ".",
  42. cardinality: 1
  43. }
  44. },
  45. mask: "(\\http://)|(\\http\\s://)|(ftp://)|(ftp\\s://)i{+}",
  46. insertMode: false,
  47. autoUnmask: false,
  48. inputmode: "url",
  49. },
  50. "ip": { //ip-address mask
  51. mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
  52. definitions: {
  53. "i": {
  54. validator: function (chrs, maskset, pos, strict, opts) {
  55. if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
  56. chrs = maskset.buffer[pos - 1] + chrs;
  57. if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
  58. chrs = maskset.buffer[pos - 2] + chrs;
  59. } else chrs = "0" + chrs;
  60. } else chrs = "00" + chrs;
  61. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  62. },
  63. cardinality: 1
  64. }
  65. },
  66. onUnMask: function (maskedValue, unmaskedValue, opts) {
  67. return maskedValue;
  68. },
  69. inputmode: "numeric",
  70. },
  71. "email": {
  72. //https://en.wikipedia.org/wiki/Domain_name#Domain_name_space
  73. //https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
  74. //should be extended with the toplevel domains at the end
  75. mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]",
  76. greedy: false,
  77. onBeforePaste: function (pastedValue, opts) {
  78. pastedValue = pastedValue.toLowerCase();
  79. return pastedValue.replace("mailto:", "");
  80. },
  81. definitions: {
  82. "*": {
  83. validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~\-]",
  84. cardinality: 1,
  85. casing: "lower"
  86. },
  87. "-": {
  88. validator: "[0-9A-Za-z\-]",
  89. cardinality: 1,
  90. casing: "lower"
  91. }
  92. },
  93. onUnMask: function (maskedValue, unmaskedValue, opts) {
  94. return maskedValue;
  95. },
  96. inputmode: "email",
  97. },
  98. "mac": {
  99. mask: "##:##:##:##:##:##"
  100. },
  101. //https://en.wikipedia.org/wiki/Vehicle_identification_number
  102. // see issue #1199
  103. "vin": {
  104. mask: "V{13}9{4}",
  105. definitions: {
  106. 'V': {
  107. validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
  108. cardinality: 1,
  109. casing: "upper"
  110. }
  111. },
  112. clearIncomplete: true,
  113. autoUnmask: true
  114. }
  115. });
  116. return Inputmask;
  117. }));