Skip to content

Commit 7962803

Browse files
committed
Bug Fixes
1 parent 9b77899 commit 7962803

1 file changed

Lines changed: 19 additions & 47 deletions

File tree

src/jquery.serialnumberinput.js

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
HTML Input Type SerialNumber
2+
HTML Input Type SerialNumber - v1.0.0
3+
License: GNU GENERAL PUBLIC LICENSE Version 3
34
GitHub: https://github.com/ish-101/HTML-Input-Type-SerialNumber
45
Dependency: jQuery 3.x.x
5-
License: GNU GENERAL PUBLIC LICENSE Version 3
66
7-
Made by Ishpreet Singh Bhasin (ish-101)
7+
Made by Ishpreet Singh Bhasin
88
Website: http://ishpreet.tech/
9+
GitHub: https://github.com/ish-101
910
*/
1011

1112
(function($)
@@ -54,60 +55,31 @@
5455
'minlength': digits.length,
5556
'maxlength': digits.length,
5657
});
57-
function main(key)
58+
target.on('keyup', function(e)
5859
{
5960
var x = target.val().split("");
60-
var correct;
61-
var recur = false;
62-
if (x.length <= digits.length)
61+
for (var i = 0; i < x.length; i++)
6362
{
64-
for (var i = 0; i < x.length; i++)
65-
{
66-
var regex_string;
67-
if (options.pieces[digits[i]].type === "character")
68-
{
69-
regex_string = options.pieces[digits[i]].pattern;
70-
}
71-
if (options.pieces[digits[i]].type === "separator")
72-
{
73-
regex_string = "[\\" + options.pieces[digits[i]].separator + "]";
74-
}
75-
correct = RegExp(regex_string).test(x[i]);
76-
if (!correct)
77-
{
78-
correct = (options.pieces[digits[i]].type === "separator");
79-
if (correct)
80-
{
81-
x[i+1] = x[i];
82-
x[i] = options.pieces[digits[i]].separator;
83-
recur = true;
84-
}
85-
else
86-
{
87-
break;
88-
}
89-
}
90-
}
91-
var y = x.join("");
92-
if (!correct)
63+
var reg_exp_pattern;
64+
if (options.pieces[digits[i]].type !== "separator")
9365
{
94-
y = y.substring(0,i);
66+
reg_exp_pattern = RegExp(options.pieces[digits[i]].pattern);
9567
}
96-
if ((x.length < digits.length) && ((key !== undefined) && ((key !== "Backspace") && (key !== "Delete"))) && (options.pieces[digits[x.length]].type === "separator"))
68+
else
9769
{
98-
y += options.pieces[digits[x.length]].separator;
99-
main();
70+
reg_exp_pattern = RegExp("[\\" + options.pieces[digits[i]].separator + "]");
10071
}
101-
target.val(y);
102-
if (recur)
72+
if (! (reg_exp_pattern.test(x[i])) )
10373
{
104-
main();
74+
break;
10575
}
10676
}
107-
}
108-
target.on('keyup', function(e)
109-
{
110-
main(e.key);
77+
if ((i < digits.length) && (options.pieces[digits[i]].type === "separator"))
78+
{
79+
x[i] = options.pieces[digits[i]].separator;
80+
i++;
81+
}
82+
target.val(x.join("").substring(0, i));
11183
});
11284
return;
11385
};

0 commit comments

Comments
 (0)