formvalidation.io - Requiring at least one field

petewinter
petewinter used Ask the Experts™
on
I am using http://formvalidation.io/ for my form validations.

I want to use this script http://formvalidation.io/examples/requiring-at-least-one-field/

However I want the input to be a "number" field instead of a "text" field. When I change to a number field it doesn't work correctly. Any idea why and what do I need to change?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
Using the type number in the input element at HTML 5 you may encounter some problems dependent from the browser. See the the following link for this issue type input (Can I use...support)
Instead of this you can set
HTML:
<input type='text' onkeypress='validate(event)' />

Open in new window


JS:
function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    if(theEvent.preventDefault){
      theEvent.preventDefault();
    }
  }
}

Open in new window

Author

Commented:
Thanks for that, but I would like the number increment/decrement if possible. Is it not possible to get the script work using a number type instead?

Author

Commented:
Found a work around, but thanks for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial