Limit input to numbers only
//------------------------------------------------ -----------------------
//
// Limit input to numbers only
// demo: $(".onlyNum").onlyNum(); restricts controls using the onlyNum class style to only input numbers
//
//------------------------------------------------ -----------------------
$.fn.onlyNum = function () {
$(this).keypress(function (event) {
var eventObj = event || e;
var keyCode = eventObj.keyCode || eventObj.which;
If ((keyCode >= 48 && keyCode <= 57))
return true;
else
return false;
}).focus(function () {
//Disable input method
This.style.imeMode = 'disabled';
}).bind("paste", function () {
//Get the contents of the clipboard
var clipboard = window.clipboardData.getData("Text");
If (/^d $/.test(clipboard))
return true;
else
return false;
});
};
Limit input to letters only
//------------------------------------------------ -----------------------
//
//Limit the input to only letters
// demo: $(".onlyAlpha").onlyAlpha(); restricts controls using the onlyNumAlpha class style to only input numbers and letters
//
//------------------------------------------------ -----------------------
$.fn.onlyAlpha = function () {
$(this).keypress(function (event) {
var eventObj = event || e;
var keyCode = eventObj.keyCode || eventObj.which;
If ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122))
return true;
else
return false;
}).focus(function () {
This.style.imeMode = 'disabled';
}).bind("paste", function () {
var clipboard = window.clipboardData.getData("Text");
If (/^[a-zA-Z] $/.test(clipboard))
return true;
else
return false;
});
};
Limit input to numbers and letters only
//------------------------------------------------ -----------------------
//
//Limit input to numbers and letters only
// demo: $(".onlyNumAlpha").onlyNumAlpha(); restricts controls using the onlyNumAlpha class style to only input numbers and letters
//
//------------------------------------------------ -----------------------
$.fn.onlyNumAlpha = function () {
$(this).keypress(function (event) {
var eventObj = event || e;
var keyCode = eventObj.keyCode || eventObj.which;
If ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122))
return true;
else
return false;
}).focus(function () {
This.style.imeMode = 'disabled';
}).bind("paste", function () {
var clipboard = window.clipboardData.getData("Text");
If (/^(d|[a-zA-Z]) $/.test(clipboard))
return true;
else
return false;
});
};