1

I'm writing some validation for a form which includes an tag with type="number". If non-numeric text is entered in the input box, getting the element with javascript and checking the value returns an empty string (in Chrome and Firefox at least).

Non-numeric text in type="number" field

var input = document.getElementById('inputId');
// ->   <input type="number" id="inputId">

console.log('The value is: ', input.value);
// ->   The value is:

console.log(typeof inputs.value);
// ->   string

Is there a way to get whatever is in the input if the entered text doesn't match the input's "type" attribute?

Jan K
  • 365
  • 1
  • 14
  • Why do you need the invalid value? – Ram Jul 03 '15 at 16:04
  • Would like to be able to throw a validation error message, but there's no way to distinguish between an empty box (valid) and invalid text entered. – Jan K Jul 03 '15 at 16:06

1 Answers1

0

Found my answer here thanks to @Michael Perrenoud https://stackoverflow.com/a/18853513/786096

TL;DR switch to type="text" if you need to customize the validation

Community
  • 1
  • 1
Jan K
  • 365
  • 1
  • 14