Used below JS script with regex.
- To allow only numbers in input field.
- To change currency value with comma like 1,000 or 1,00,000 on user type value in input.
Below codes working in all major browser expect in safari. Getting this error only in safari. Not sure how to fix this regex without affecting other working browsers.
SyntaxError: Invalid regular expression: invalid group specifier name
$('input.input-num').on('change click keyup input paste',(function (event) {
$(this).val(function (index, value) {
return value.replace(/(?!\.)\D/g, "").replace(/(?<=\..*)\./g, "");
});
}));
$('input.input-currency').on('change click keyup input paste',(function (event) {
$(this).val(function (index, value) {
return value.replace(/(?!\.)\D/g, "").replace(/(?<=\..*)\./g, "").replace(/(?<=\.\d\d).*/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
}));