Gossamer Forum
Home : Products : DBMan : Customization :

Allow one word only

Quote Reply
Allow one word only
Is it possible to oblige the user to include one word only (i.e. no space) in a field ?
Quote Reply
Re: [jigme] Allow one word only In reply to
if ($in{'field'} =~ /\s+/) { print qq|ERROR! You are not allowed to enter whitespace in "field".<br>|;}
kellner
Quote Reply
Re: [kellner] Allow one word only In reply to
You don't need the + Angelic

/\s/
Quote Reply
Re: [RedRum] Allow one word only In reply to
True - try the code as above minus the plus Wink
kellner
Quote Reply
Re: [kellner] Allow one word only In reply to
Thank you very much for your fast answer.

But i do not know in which file and sub to place this code.

Cheers

J
Quote Reply
Re: [jigme] Allow one word only In reply to
Depends on where you want to check. I would put it into the sub validate_record in db.cgi. That way, this is checked whenever a record is added or modified.

There you see a line starting with if ($#input_err+1 > 0) { ....

Add the code before this line:

if ($in{'fieldname'} =~ /\s/) { push (@input_err, "ERROR: <b>fieldname</b> must not contain whitespace");}
kellner
Quote Reply
Re: [kellner] Allow one word only In reply to
Thanks a lot. it works fine.

Can you tell me how to avoid anything else in a field. for ex, i don t want any letter W to be included in one field.

i wonder also if there is a way to forbid any HTML tag in one field only.

Cheers
Quote Reply
Re: [jigme] Allow one word only In reply to
/W/ for the letter w :)

/<[^>]+>/ ....for html

Last edited by:

RedRum: Mar 5, 2002, 5:26 AM