I'd do it client side with a javascript validation function.
PHP Code:
function validateNumberEntry(e) {
var MAX_VAL = 20; // Change maximum number here.
var MIN_VAL = 1; // Change minimum number here.
var el = getElementById(e);
var v = el.value;
if (isNumber(v)) {
if (v<MIN_VAL||v>MAX_VAL) {
el.value = '';
alert('Invalid Input. Valid number range is ' + MIN_VAL + ' through' + MAX_VAL);
}
} else {
el.value = '';
alert('Invalid Input. Valid number range is ' + MIN_VAL + ' through' + MAX_VAL);
}
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
Then use the HTML5 element.oninput event to call the function.
HTML Code:
<input type="text" id="lot1" name="lot1" oninput="validateNumberEntry(lot1);"></input>
<input type="text" id="lot2" name="lot2" oninput="validateNumberEntry(lot2);"></input>
<input type="text" id="lot3" name="lot3" oninput="validateNumberEntry(lot3);"></input>
<input type="text" id="lot4" name="lot4" oninput="validateNumberEntry(lot4);"></input>
<input type="text" id="lot5" name="lot5" oninput="validateNumberEntry(lot5);"></input>
<input type="text" id="lot6" name="lot6" oninput="validateNumberEntry(lot6);"></input>
This way, you validate the input client side, before the form is POSTed; no callback is needed to alert the user to invalid entries.
Make sure you revalidate your values within the page you POST to though, before using them.
Bookmarks