Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Formatting an document input field that shows automatically dots and hyphens but not allowing them when submitting the form

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!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 ;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!