tests_regex.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. export default function(qunit, $, Inputmask) {
  2. qunit.module("Regex masks");
  3. qunit.test("inputmask({ regex: \"[0-9]*\"});", function(assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask({
  8. regex: "[0-9]*"
  9. }).mask(testmask);
  10. testmask.focus();
  11. $("#testmask").Type("123abc45");
  12. assert.equal(testmask.value, "12345", "Result " + testmask.value);
  13. });
  14. qunit.test("inputmask({ regex: \"[0-9]*\"}); ~ isComplete", function(assert) {
  15. var $fixture = $("#qunit-fixture"), done = assert.async();
  16. $fixture.append('<input type="text" id="testmask" />');
  17. var testmask = document.getElementById("testmask");
  18. Inputmask({
  19. regex: "[0-9]*",
  20. oncomplete: function() {
  21. assert.equal(testmask.value, "1", "Result " + testmask.value);
  22. done();
  23. }
  24. }).mask(testmask);
  25. testmask.focus();
  26. $("#testmask").SendKey("1");
  27. });
  28. qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
  29. var $fixture = $("#qunit-fixture");
  30. $fixture.append('<input type="text" id="testmask" />');
  31. var testmask = document.getElementById("testmask");
  32. Inputmask({regex: "[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
  33. }).mask(testmask);
  34. testmask.focus();
  35. $("#testmask").Type("123abc45");
  36. assert.equal(testmask.value, "123abc45", "Result " + testmask.value);
  37. });
  38. qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u0451]+[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
  39. var $fixture = $("#qunit-fixture");
  40. $fixture.append('<input type="text" id="testmask" />');
  41. var testmask = document.getElementById("testmask");
  42. Inputmask({
  43. regex: "[A-Za-z\u0410-\u044F\u0401\u0451]+[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
  44. }).mask(testmask);
  45. testmask.focus();
  46. $("#testmask").Type("123abc45");
  47. assert.equal(testmask.value, "abc45", "Result " + testmask.value);
  48. });
  49. qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u0451]{1}[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
  50. var $fixture = $("#qunit-fixture");
  51. $fixture.append('<input type="text" id="testmask" />');
  52. var testmask = document.getElementById("testmask");
  53. Inputmask({
  54. regex: "[A-Za-z\u0410-\u044F\u0401\u0451]{1}[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
  55. }).mask(testmask);
  56. testmask.focus();
  57. $("#testmask").Type("123abc45");
  58. assert.equal(testmask.value, "abc45", "Result " + testmask.value);
  59. });
  60. qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
  61. var $fixture = $("#qunit-fixture");
  62. $fixture.append('<input type="text" id="testmask" />');
  63. var testmask = document.getElementById("testmask");
  64. Inputmask({
  65. regex: "[-]?(([1-8][0-9])|[1-9]0?)"
  66. }).mask(testmask);
  67. testmask.focus();
  68. $("#testmask").Type("90");
  69. assert.equal(testmask.value, "90", "Result " + testmask.value);
  70. });
  71. qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
  72. var $fixture = $("#qunit-fixture");
  73. $fixture.append('<input type="text" id="testmask" />');
  74. var testmask = document.getElementById("testmask");
  75. Inputmask({
  76. regex: "[-]?(([1-8][0-9])|[1-9]0?)"
  77. }).mask(testmask);
  78. testmask.focus();
  79. $("#testmask").Type("0");
  80. assert.equal(testmask.value, "", "Result " + testmask.value);
  81. });
  82. qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
  83. var $fixture = $("#qunit-fixture");
  84. $fixture.append('<input type="text" id="testmask" />');
  85. var testmask = document.getElementById("testmask");
  86. Inputmask({
  87. regex: "[-]?(([1-8][0-9])|[1-9]0?)"
  88. }).mask(testmask);
  89. testmask.focus();
  90. $("#testmask").Type("-78");
  91. assert.equal(testmask.value, "-78", "Result " + testmask.value);
  92. });
  93. qunit.test("inputmask({ regex: \"[a-za-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*)?\" - simple regex email", function(assert) {
  94. var $fixture = $("#qunit-fixture");
  95. $fixture.append('<input type="text" id="testmask" />');
  96. var testmask = document.getElementById("testmask");
  97. Inputmask({
  98. regex: "[a-za-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*)?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"
  99. }).mask(testmask);
  100. testmask.focus();
  101. $("#testmask").Type("some.body@mail.com");
  102. assert.equal(testmask.value, "some.body@mail.com", "Result " + testmask.value);
  103. });
  104. qunit.test("inputmask({ regex: \"[a-za-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*)?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\" - complexer regex email", function(assert) {
  105. var $fixture = $("#qunit-fixture");
  106. $fixture.append('<input type="text" id="testmask" />');
  107. var testmask = document.getElementById("testmask");
  108. Inputmask({
  109. regex: "[a-za-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*)?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"
  110. }).mask(testmask);
  111. testmask.focus();
  112. $("#testmask").Type("denise.van.de.cruys@mail.com");
  113. assert.equal(testmask.value, "denise.van.de.cruys@mail.com", "Result " + testmask.value);
  114. });
  115. qunit.test("inputmask({ regex: \"(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))\" - mrpanacs regex 1-123-4562", function(assert) {
  116. var $fixture = $("#qunit-fixture");
  117. $fixture.append('<input type="text" id="testmask" />');
  118. var testmask = document.getElementById("testmask");
  119. Inputmask({
  120. regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
  121. }).mask(testmask);
  122. testmask.focus();
  123. $("#testmask").Type("1-123-4562");
  124. assert.equal(testmask.value, "1-123-4562", "Result " + testmask.value);
  125. });
  126. qunit.test("inputmask({ regex: \"(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))\" - mrpanacs regex 20-222-2222", function(assert) {
  127. var $fixture = $("#qunit-fixture");
  128. $fixture.append('<input type="text" id="testmask" />');
  129. var testmask = document.getElementById("testmask");
  130. Inputmask({
  131. regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
  132. }).mask(testmask);
  133. testmask.focus();
  134. $("#testmask").Type("20-222-2222");
  135. assert.equal(testmask.value, "20-222-2222", "Result " + testmask.value);
  136. });
  137. qunit.test("inputmask({ regex: \"(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))\" - mrpanacs regex 22-222-234", function(assert) {
  138. var $fixture = $("#qunit-fixture");
  139. $fixture.append('<input type="text" id="testmask" />');
  140. var testmask = document.getElementById("testmask");
  141. Inputmask({
  142. regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
  143. }).mask(testmask);
  144. testmask.focus();
  145. $("#testmask").Type("22-222-234");
  146. assert.equal(testmask.value, "22-222-234", "Result " + testmask.value);
  147. });
  148. qunit.test("inputmask({ regex: \"(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))\" - mrpanacs regex 70-12-34", function(assert) {
  149. var $fixture = $("#qunit-fixture");
  150. $fixture.append('<input type="text" id="testmask" />');
  151. var testmask = document.getElementById("testmask");
  152. Inputmask({
  153. regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
  154. }).mask(testmask);
  155. testmask.focus();
  156. $("#testmask").Type("70-12-34");
  157. assert.equal(testmask.value, "70-123", "Result " + testmask.value);
  158. });
  159. qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" - arame regex 12", function(assert) {
  160. var $fixture = $("#qunit-fixture");
  161. $fixture.append('<input type="text" id="testmask" />');
  162. var testmask = document.getElementById("testmask");
  163. Inputmask({
  164. regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
  165. }).mask(testmask);
  166. testmask.focus();
  167. $("#testmask").Type("12");
  168. assert.equal(testmask.value, "12", "Result " + testmask.value);
  169. });
  170. qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" } - arame regex 12.5", function(assert) {
  171. var $fixture = $("#qunit-fixture");
  172. $fixture.append('<input type="text" id="testmask" />');
  173. var testmask = document.getElementById("testmask");
  174. Inputmask({
  175. regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
  176. }).mask(testmask);
  177. testmask.focus();
  178. $("#testmask").Type("12.5");
  179. assert.equal(testmask.value, "12.5", "Result " + testmask.value);
  180. });
  181. qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" } - arame regex 12.75", function(assert) {
  182. var $fixture = $("#qunit-fixture");
  183. $fixture.append('<input type="text" id="testmask" />');
  184. var testmask = document.getElementById("testmask");
  185. Inputmask({
  186. regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
  187. }).mask(testmask);
  188. testmask.focus();
  189. $("#testmask").Type("12.75");
  190. assert.equal(testmask.value, "12.75", "Result " + testmask.value);
  191. });
  192. qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex abcdef", function(assert) {
  193. var $fixture = $("#qunit-fixture");
  194. $fixture.append('<input type="text" id="testmask" />');
  195. var testmask = document.getElementById("testmask");
  196. Inputmask({
  197. regex: "(abc)+(def)",
  198. jitMasking: true
  199. }).mask(testmask);
  200. testmask.focus();
  201. $("#testmask").Type("abcdef");
  202. assert.equal(testmask.value, "abcdef", "Result " + testmask.value);
  203. });
  204. qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex 123a4b5c6d7e8f", function(assert) {
  205. var $fixture = $("#qunit-fixture");
  206. $fixture.append('<input type="text" id="testmask" />');
  207. var testmask = document.getElementById("testmask");
  208. Inputmask({
  209. regex: "(abc)+(def)",
  210. jitMasking: true
  211. }).mask(testmask);
  212. testmask.focus();
  213. $("#testmask").Type("123a4b5c6d7e8f");
  214. assert.equal(testmask.value, "abcdef", "Result " + testmask.value);
  215. });
  216. qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex abcabcdef", function(assert) {
  217. var $fixture = $("#qunit-fixture");
  218. $fixture.append('<input type="text" id="testmask" />');
  219. var testmask = document.getElementById("testmask");
  220. Inputmask({
  221. regex: "(abc)+(def)",
  222. jitMasking: true
  223. }).mask(testmask);
  224. testmask.focus();
  225. $("#testmask").Type("abcabcdef");
  226. assert.equal(testmask.value, "abcabcdef", "Result " + testmask.value);
  227. });
  228. qunit.test("inputmask({ regex: \"(abc){2,4}(def)\" }); - Flyarbonkers regex abcafebcaefbfcabcdef", function(assert) {
  229. var $fixture = $("#qunit-fixture");
  230. $fixture.append('<input type="text" id="testmask" />');
  231. var testmask = document.getElementById("testmask");
  232. Inputmask({
  233. regex: "(abc){2,4}(def)",
  234. jitMasking: true
  235. }).mask(testmask);
  236. testmask.focus();
  237. $("#testmask").Type("abcafebcaefbfcabcdef");
  238. assert.equal(testmask.value, "abcabcabcabcdef", "Result " + testmask.value);
  239. });
  240. qunit.test("inputmask({regex: \"[а-яА-Я\\s]*\"}) - type space - SilentImp", function(assert) {
  241. var $fixture = $("#qunit-fixture");
  242. $fixture.append('<input type="text" id="testmask" />');
  243. var testmask = document.getElementById("testmask");
  244. Inputmask({
  245. regex: "[а-яА-Я\\s]*"
  246. }).mask(testmask);
  247. testmask.focus();
  248. $("#testmask").SendKey(Inputmask.keyCode.SPACE);
  249. assert.equal(testmask.value, " ", "Result " + testmask.value);
  250. });
  251. };