$(document).on("input", ".money", function(e) {
console.log(moneyonly($(this).val()))
if (moneyonly($(this).val())) {
return true;
}
return false;
});
function moneyonly(amount) {
var boo = false;
if ((/^\d*(?:\.\d{2})?$/g).test(amount)) {
boo = true;
}
return boo;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="money" id="">
Regex is ok. Even if false it is still typing in the input. How to not allow?
How to allow only the format that is assigned in regex? Any idea is appreciated