Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input type number does not allow comma separator

Tags:

html

I have a number input field:

<input type="number" class="field" min="0" step="0.01" required>

My language is en

As soon as I type 12, the value returns nothing it's empty, not NaN, undefined or 0 just an empty log

enter image description here

Is there a way to allow both comma and period? Or do I have to fallback to a simple input with some custom validation?

like image 386
michael Avatar asked Apr 25 '26 15:04

michael


1 Answers

You can try this custom validation form for number you can allow it to insert comma , and dot . except for letters and other symbols. Thanks

JAVASCRIPT

function filter_letters_and_symbols(evt){

  var hold = String.fromCharCode(evt.which);

  if((/[a-z A-Z*!@#$%^&*()_/[\]}=+><{?":;'"|]/.test(hold))){

    evt.preventDefault();

  }
}

HTML

<input type="text" class="field" min="0" step="0.01" onkeypress="filter_letters_and_symbols(event)" required>
like image 74
Jesper Martinez Avatar answered Apr 28 '26 04:04

Jesper Martinez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!