Skip to content

Instantly share code, notes, and snippets.

@al5dy
Created March 8, 2023 07:58
Show Gist options
  • Save al5dy/6ba97be2c6ff72788b9bda568039e2b0 to your computer and use it in GitHub Desktop.
Save al5dy/6ba97be2c6ff72788b9bda568039e2b0 to your computer and use it in GitHub Desktop.
Allow input only numbers, dot and comma for field
$("[data-allow-comma]").on("keypress keyup blur",function (event) {
$(this).val($(this).val().replace(/[^0-9\.|\,]/g,''));
if(event.which == 44)
{
return true;
}
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57 )) {
event.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment