123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- export default function(qunit, $, Inputmask) {
- qunit.module("Regex masks");
- qunit.test("inputmask({ regex: \"[0-9]*\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[0-9]*"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("123abc45");
- assert.equal(testmask.value, "12345", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[0-9]*\"}); ~ isComplete", function(assert) {
- var $fixture = $("#qunit-fixture"), done = assert.async();
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[0-9]*",
- oncomplete: function() {
- assert.equal(testmask.value, "1", "Result " + testmask.value);
- done();
- }
- }).mask(testmask);
- testmask.focus();
- $("#testmask").SendKey("1");
- });
- qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({regex: "[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("123abc45");
- assert.equal(testmask.value, "123abc45", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u0451]+[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[A-Za-z\u0410-\u044F\u0401\u0451]+[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("123abc45");
- assert.equal(testmask.value, "abc45", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[A-Za-z\u0410-\u044F\u0401\u0451]{1}[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[A-Za-z\u0410-\u044F\u0401\u0451]{1}[A-Za-z\u0410-\u044F\u0401\u04510-9]*"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("123abc45");
- assert.equal(testmask.value, "abc45", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[-]?(([1-8][0-9])|[1-9]0?)"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("90");
- assert.equal(testmask.value, "90", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[-]?(([1-8][0-9])|[1-9]0?)"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("0");
- assert.equal(testmask.value, "", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"[-]?(([1-8][0-9])|[1-9]0?)\"});", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[-]?(([1-8][0-9])|[1-9]0?)"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("-78");
- assert.equal(testmask.value, "-78", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- 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])?"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("some.body@mail.com");
- assert.equal(testmask.value, "some.body@mail.com", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- 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])?"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("denise.van.de.cruys@mail.com");
- assert.equal(testmask.value, "denise.van.de.cruys@mail.com", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("1-123-4562");
- assert.equal(testmask.value, "1-123-4562", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("20-222-2222");
- assert.equal(testmask.value, "20-222-2222", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("22-222-234");
- assert.equal(testmask.value, "22-222-234", "Result " + testmask.value);
- });
- 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) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70)-([0-9]{3}-[0-9]{4}))"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("70-12-34");
- assert.equal(testmask.value, "70-123", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" - arame regex 12", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12");
- assert.equal(testmask.value, "12", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" } - arame regex 12.5", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12.5");
- assert.equal(testmask.value, "12.5", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" } - arame regex 12.75", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("12.75");
- assert.equal(testmask.value, "12.75", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex abcdef", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(abc)+(def)",
- jitMasking: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("abcdef");
- assert.equal(testmask.value, "abcdef", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex 123a4b5c6d7e8f", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(abc)+(def)",
- jitMasking: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("123a4b5c6d7e8f");
- assert.equal(testmask.value, "abcdef", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"(abc)+(def)\" }); - Flyarbonkers regex abcabcdef", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(abc)+(def)",
- jitMasking: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("abcabcdef");
- assert.equal(testmask.value, "abcabcdef", "Result " + testmask.value);
- });
- qunit.test("inputmask({ regex: \"(abc){2,4}(def)\" }); - Flyarbonkers regex abcafebcaefbfcabcdef", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "(abc){2,4}(def)",
- jitMasking: true
- }).mask(testmask);
- testmask.focus();
- $("#testmask").Type("abcafebcaefbfcabcdef");
- assert.equal(testmask.value, "abcabcabcabcdef", "Result " + testmask.value);
- });
- qunit.test("inputmask({regex: \"[а-яА-Я\\s]*\"}) - type space - SilentImp", function(assert) {
- var $fixture = $("#qunit-fixture");
- $fixture.append('<input type="text" id="testmask" />');
- var testmask = document.getElementById("testmask");
- Inputmask({
- regex: "[а-яА-Я\\s]*"
- }).mask(testmask);
- testmask.focus();
- $("#testmask").SendKey(Inputmask.keyCode.SPACE);
- assert.equal(testmask.value, " ", "Result " + testmask.value);
- });
- };
|