I'm currently working in user creation login page for an e-commerce and I need to achieve something like this: https://drive.google.com/file/d/1JJBeZG-oyzrh8vCDRMjfv03oGDjrWwZw/view?usp=sharing (The video has to be seen on fullscreen, otherwise it'll be too small to detail anything)
Thing is I should not allow any special characters when the form is submitted and I think I already solved that:
$('#login_form #document').on('input', function() {
this.value = this.value.toLocaleUpperCase();
let count = this.selectionStart,
regex = /[^a-z0-9]/gi,
value = $(this).val();
console.log(value)
if(regex.test(value)) {
$(this).val(value.replace(regex, ''));
count--;
}
this.setSelectionRange(count, count);
});
But I can't really think in a way to show the dots and hyphens and not allowing them on submit.
Also, any recommendation to improve the code will be well receive. Thanks in advance!
Just keep the formatting from your front-end, do some reverse reformatting in backend instead, example you input 10,000.00 then you submit it using backend PHP just replace "," str_replace(',', '', '10,000.00') then you will get 10000.00 then use $new_number = (float)10000.00
$input_number = '10,000.00';
$input_number_no_comma = str_replace(',', '', $input_number);
$input_number_new = (float)$input_number_no_comma;
echo $input_number_new ;