Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxLength settings and fix maxLength when used allowNegative and prefix #200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/jquery.maskMoney.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
decimal: ".",
precision: 2,
allowZero: false,
allowNegative: false
allowNegative: false,
maxLength: undefined
}, parameters);

return this.each(function () {
Expand Down Expand Up @@ -122,13 +123,22 @@
} // getInputSelection

function canInputMoreNumbers() {
var haventReachedMaxLength = !($input.val().length >= $input.attr("maxlength") && $input.attr("maxlength") >= 0),
selection = getInputSelection(),
start = selection.start,
end = selection.end,
haveNumberSelected = (selection.start !== selection.end && $input.val().substring(start, end).match(/\d/)) ? true : false,
startWithZero = ($input.val().substring(0, 1) === "0");
var integerValue = $input.val().match(/\d+/g).join("");

var haventReachedMaxLength = false;
if (settings.maxLength) {
haventReachedMaxLength = integerValue.length < settings.maxLength;
} else {
haventReachedMaxLength = !($input.val().length >= $input.attr("maxlength") && $input.attr("maxlength") >= 0);
}

var selection = getInputSelection();
var haveNumberSelected = $input.val().substring(selection.start, selection.end).match(/\d/g) != null;

var startWithZero = (integerValue.substring(0, 1) === "0");

return haventReachedMaxLength || haveNumberSelected || startWithZero;

}

function setCursorPosition(pos) {
Expand Down