I have tried to validate input field by using a javascript/jQuery code. This is work fine with input type text and not support in number type. Input type 'number' does not work at all in FireFox.
My client wants the field to show number pad in mobile when the user starts to type and in the case of user try to type words should remove the words.
HTML:
<input name="pricePerHour" id="pricePerHour" type="number" class="form-control" placeholder="Price Per Hour" required />
<br><br>
<input name="pricePerHour" id="costPerHour" type="text" class="form-control" placeholder="Cost Per Hour" required />
Javascript:
$("#pricePerHour,#costPerHour").on("keyup", function() {
var valid = /^\d{0,4}(\.\d{0,2})?$/.test(this.value),
val = this.value;
if (!valid) {
this.value = val.substring(0, val.length - 1);
}
});