I have a form that has five fields that are all set to maxlength="2".
Basically, i want the only values that can be entered to either be a one or two digit integer, because calculations are performed on these fields before the values are stored in the database.
Is there any jquery that will not let a user even enter a value that isnt an integer?
Also what would be the best way to validate this with both jquery and php? I have found some ways of doing it, but i need to make sure its secure, avoiding characters, -2, .1 etc
SOLVED
For the php part i used
if(!ctype_digit($_POST['value']))
which only allows for positive whole numbers
And for javascript
$('.inputQuantity').keyup(function(){
this.value = this.value.replace(/[^0-9\.]/g,'');
});
which deletes any entry made into the input field that is not a number.
Both above work, although i think some people prefer to use focusout(function() rather than keyup(function() ;)