jquery.inputmask.extensions.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Optional extensions on the jquery.inputmask base
  8. */
  9. (function ($) {
  10. //extra definitions
  11. $.extend($.inputmask.defaults.definitions, {
  12. 'A': {
  13. validator: "[A-Za-z]",
  14. cardinality: 1,
  15. casing: "upper" //auto uppercasing
  16. },
  17. '#': {
  18. validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
  19. cardinality: 1,
  20. casing: "upper"
  21. }
  22. });
  23. $.extend($.inputmask.defaults.aliases, {
  24. 'url': {
  25. mask: "ir",
  26. placeholder: "",
  27. separator: "",
  28. defaultPrefix: "http://",
  29. regex: {
  30. urlpre1: new RegExp("[fh]"),
  31. urlpre2: new RegExp("(ft|ht)"),
  32. urlpre3: new RegExp("(ftp|htt)"),
  33. urlpre4: new RegExp("(ftp:|http|ftps)"),
  34. urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"),
  35. urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"),
  36. urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"),
  37. urlpre8: new RegExp("(ftp://|ftps://|http://|https://)")
  38. },
  39. definitions: {
  40. 'i': {
  41. validator: function (chrs, buffer, pos, strict, opts) {
  42. return true;
  43. },
  44. cardinality: 8,
  45. prevalidator: (function () {
  46. var result = [], prefixLimit = 8;
  47. for (var i = 0; i < prefixLimit; i++) {
  48. result[i] = (function () {
  49. var j = i;
  50. return {
  51. validator: function (chrs, buffer, pos, strict, opts) {
  52. if (opts.regex["urlpre" + (j + 1)]) {
  53. var tmp = chrs, k;
  54. if (((j + 1) - chrs.length) > 0) {
  55. tmp = buffer.join('').substring(0, ((j + 1) - chrs.length)) + "" + tmp;
  56. }
  57. var isValid = opts.regex["urlpre" + (j + 1)].test(tmp);
  58. if (!strict && !isValid) {
  59. pos = pos - j;
  60. for (k = 0; k < opts.defaultPrefix.length; k++) {
  61. buffer[pos] = opts.defaultPrefix[k]; pos++;
  62. }
  63. for (k = 0; k < tmp.length - 1; k++) {
  64. buffer[pos] = tmp[k]; pos++;
  65. }
  66. return { "pos": pos };
  67. }
  68. return isValid;
  69. } else {
  70. return false;
  71. }
  72. }, cardinality: j
  73. };
  74. })();
  75. }
  76. return result;
  77. })()
  78. },
  79. "r": {
  80. validator: ".",
  81. cardinality: 50
  82. }
  83. },
  84. insertMode: false,
  85. autoUnmask: false
  86. },
  87. "ip": { //ip-address mask
  88. mask: ["[[x]y]z.[[x]y]z.[[x]y]z.x[yz]", "[[x]y]z.[[x]y]z.[[x]y]z.[[x]y][z]"],
  89. definitions: {
  90. 'x': {
  91. validator: "[012]",
  92. cardinality: 1,
  93. definitionSymbol: "i"
  94. },
  95. 'y': {
  96. validator: function (chrs, buffer, pos, strict, opts) {
  97. if (pos - 1 > -1 && buffer[pos - 1] != ".")
  98. chrs = buffer[pos - 1] + chrs;
  99. else chrs = "0" + chrs;
  100. return new RegExp("2[0-5]|[01][0-9]").test(chrs);
  101. },
  102. cardinality: 1,
  103. definitionSymbol: "i"
  104. },
  105. 'z': {
  106. validator: function (chrs, buffer, pos, strict, opts) {
  107. if (pos - 1 > -1 && buffer[pos - 1] != ".") {
  108. chrs = buffer[pos - 1] + chrs;
  109. if (pos - 2 > -1 && buffer[pos - 2] != ".") {
  110. chrs = buffer[pos - 2] + chrs;
  111. } else chrs = "0" + chrs;
  112. } else chrs = "00" + chrs;
  113. return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
  114. },
  115. cardinality: 1,
  116. definitionSymbol: "i"
  117. }
  118. }
  119. }
  120. });
  121. })(jQuery);