View Full Version : Text only fields

06-25-2006, 10:55 PM
Hello all

I have been searching for about an hour for a functions that will not allow numbers in a text fields and have no luck.

There are lots of code out there written for 'numeric only' fields but does anyone have a sample of a fields that only allows TEXT?

Please post the full code (form, script, etc.)

06-26-2006, 08:10 AM
You'll find it here -


Although I gues you'd have to tweak it a bit to adapt to what you require.

06-26-2006, 09:30 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<input onkeyup="this.value=this.value.replace(/\d/g,'');" />


06-26-2006, 06:55 PM
Vic where is the actual script?

06-26-2006, 07:28 PM
the important part is the regular expression:


If you put this into string.match, it will return the number of numbers in the text, so:

"abcdefg".match(/\d/) == 0

"abc2defg".match(/\d/) == 1

"ab3cde4fg".match(/\d/) == 2

So you can test input.value.match(/\d/) for being greater than 0 to tell if there are numbers or not.

06-26-2006, 07:56 PM
Vic where is the actual script?

this is the bit that does the filter



if any character is a digit replace it with ''

\d = any digit

g = any character in the string

06-27-2006, 03:19 AM
Guys I am a newbie which is why I am asking questions on the list.

posting pieces of code is still like a foreign language to me.

Can you send me the script and form field syntax?