...

View Full Version : Text only fields



torrentgirl
06-25-2006, 09: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.)

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

http://www.jsmadeeasy.com/javascripts/Forms/list_test.asp

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

vwphillips
06-26-2006, 08:30 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<head>
<title></title>
</head>

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

</html>

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

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

/\d/

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.

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


this is the bit that does the filter

.replace(/\d/g,'');

means

if any character is a digit replace it with ''

\d = any digit

g = any character in the string

torrentgirl
06-27-2006, 02: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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum