0

With an input of type number, how to get the TEXT displayed on the input (not the value) when the value is invalid.

Exemple :

<form>
   <input type="number" id="num" step="any">
</form>

CodePen

If the user enter the invalid value "0..1" (instead of "0.1"), document.getElementById('num').value return an empty string.
How to get with JavaScript the text "0..1" ?

Why this question ?

The goal is to provide better validation message. The input of type number is "tricky" and the behavior inconsistent, if the user enter " 5" in Firefox, it's an invalid number, I want to be able to display in my validation message why the number is invalid.

PlageMan
  • 708
  • 7
  • 21
  • 1
    If you're validating it with JavaScript, the easiest way would be to set an input type text and to check then with js only... – kevinniel Mar 21 '18 at 15:18
  • I found method `window.num.reportValidity()` and `.checkValidity()`. it return false in case of invalid value, and true otherwise. – degr Mar 21 '18 at 15:19
  • @Logar : Ok it's the same question, i should have search with the term "raw value", thanks. – PlageMan Mar 21 '18 at 15:23

0 Answers0