ipruthi
08-04-2002, 03:13 PM
Hi,
The following function allows "only" numbers to be typed into a textfield. Can this be altered so that "only" letters would be allowed?? I want to use this to gather the first 3 letters of the last name, and I want the visitor to enter letters only, instead of trying to hack my application.:D
Function goes...
function disallowLetters(eventObj, obj)
{
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==46){
if (str.indexOf(".")>0){
return false
}
}
if((keyCode<48 || keyCode >58) && (keyCode != 46)){ // Allow only integers and decimal points
return false
}
return true
}
... and then you call it as:
<input... onKeyPress="return disallowLetters(event, this)">
Thanks for all the help! You guys are great!
I.
The following function allows "only" numbers to be typed into a textfield. Can this be altered so that "only" letters would be allowed?? I want to use this to gather the first 3 letters of the last name, and I want the visitor to enter letters only, instead of trying to hack my application.:D
Function goes...
function disallowLetters(eventObj, obj)
{
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==46){
if (str.indexOf(".")>0){
return false
}
}
if((keyCode<48 || keyCode >58) && (keyCode != 46)){ // Allow only integers and decimal points
return false
}
return true
}
... and then you call it as:
<input... onKeyPress="return disallowLetters(event, this)">
Thanks for all the help! You guys are great!
I.