I found this function but am having difficulty incorporating it into my function
example
Code:
$(document).ready(function() {
$("#txtboxToFilter").keydown(function(event) {
// Allow: backspace, delete, tab and escape
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
});
my function
Code:
$('#paxphoneno,#paxphoneno2,#bkphoneno,#bkpaxphoneno,#bkpaxphoneno2').keypress(function (e) {
$(this).next('.error').remove();
if (e.which < 48 || e.which > 57) {
$(this).after('<span class="error">Please only use numbers</span>');
return false;
}
}).keyup(function(e) {
if (this.value.substr(0, 1) === "0") {
$(this).after('<span class="error">Please do not enter 0 as the first character</span>');
this.value = this.value.replace(/^(0+)/, '');
$(this).trigger('change');
}
}).blur(function () {
$(this).next('.error').remove();
});
Bookmarks