function AcceptNumber(objtextbox)
{
var exp = /[^\d]/g;
objtextbox.value = objtextbox.value.replace(exp,'');
}
The variable exp is the regular expression for digits only."[^\d]" means that all characters of keyboard except digits."/g" is used to validate all occurrences in a textbox.
call this method in "onkeyup" event, whenever we type letter, The value of whole textbox is validated and Characters other than digits are replace with empty string ''


No comments:
Post a Comment