0

I'm using the jquery validation plugin and attempting to validate an <input type="number"/> to ensure it is a number since Safari Mobile doesn't support the standard HTML5 validations. It works fine if its type="text". Has anyone gotten this to work correctly or is it just a limit of the plugin?

Here's an example, if you enter a non-number it works correctly for the two text fields but not the 1st field (number input):

http://jsfiddle.net/rq5ra/397/

Sparky
  • 98,165
  • 25
  • 199
  • 285
turbo2oh
  • 2,849
  • 6
  • 34
  • 46
  • I've seen issues with `type="number"` and the jQuery Validate plugin. However, keep in mind, that while using the jQuery Validate plugin, all HTML5 validation is automatically disabled by the plugin anyway. – Sparky Jul 02 '14 at 18:01
  • @Sparky thats fine, ideally I'd like to keep the type as number so the iOS user will see the correct keyboard, but still validate it as a number – turbo2oh Jul 02 '14 at 18:03
  • Until the developer fixes the issue, you can't. – Sparky Jul 02 '14 at 18:04
  • use tel insted of number – http://stackoverflow.com/questions/18677323/html5-input-type-number-value-is-empty-in-webkit-if-has-spaces-or-non-numeric-ch – Krzysztof Safjanowski Jul 02 '14 at 18:44
  • @KrzysztofSafjanowski thanks for the suggestion, cool option except in this instance I need to be able to do decimal points as well. – turbo2oh Jul 02 '14 at 18:48
  • You can add 'required' to this buggy field. For more details error comes from check method and from line `var val = this.elementValue(element);` String inside field with type number is evaluated to empty string. Empty string is valid number (wtf?) You can ask how to fix this – solution will have something like `element.validity.valid` checker – Krzysztof Safjanowski Jul 02 '14 at 18:57
  • 1
    **NOTE**: The `type="number"` bug has reportedly been resolved as of jQuery Validate version 1.13 ~ See: [github.com/jzaefferer/jquery-validation/releases/tag/1.13.0](https://github.com/jzaefferer/jquery-validation/releases/tag/1.13.0) – Sparky Jul 04 '14 at 17:33
  • @sparky awesome! thanks for coming back to this question with an update. – turbo2oh Jul 04 '14 at 21:39

0 Answers0