...

View Full Version : Letters-only text-field



ipruthi
08-04-2002, 04: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.

nolachrymose
08-04-2002, 05:29 PM
function isAlpha(evt) {
var e=new Object();
e.which=(evt.which)?evt.which:event.keyCode;
return (e.which>=97 && e.which<=122);
}

Hope that helps!

Happy coding! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum