One of the Figleaf guys posted a much nicer version of this using regex a
month or so back, so you may want to check the archives.
Here is what I use to keep people from typing characters in text fields
though.
This goes in head
<SCRIPT TYPE="text/javascript">
<!--
function letternumber(e)
{
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;
// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789 ").indexOf(keychar) > -1))
return true;
else
return false;
}
//-->
</SCRIPT>
Call it with this in you input tag.
onKeyPress="return letternumber(event)"
Just change the characters to whatever you want. It will work for spaces
also.
Of course though, you should never rely on javascript...
jon
----- Original Message -----
From: "W Luke" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Thursday, March 22, 2001 7:39 PM
Subject: Textbox validation
> Hi,
>
> On one textbox I need to prohibit users entering more than one word - I
> don't want them to enter a space. What's the best way of doing this -
> Javascript, or Cold Fusion after the form has been posted?
>
> Thanks.
>
> Will
> --
> [EMAIL PROTECTED] -=- www.lukrative.com
> Local-Advertising -=- www.localbounty.com
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists