Gossamer Forum
Home : Products : DBMan : Customization :

Control on LOWER CASES

Quote Reply
Control on LOWER CASES
Some users write their whole records with UPPER CASES.
It is difficult to read.

By entering [a-z] in the defaults of fields, it is possible to forbid the use of UPPER CASES.

Now, is there a way of allowing only sentence caps. (UPPER CASES allowed only at the beginning of sentences ) ?

Thanks.
Quote Reply
Re: Control on LOWER CASES In reply to
You could probably come up with a regular expression that would only allow lower case letters, but I think it's a little nasty to tell somebody they made a mistake just because they had their caps lock on. Instead, you could add some code that would convert things to the correct case before it's added.

It depends on what you want to do. Do you want to make all the fields lower case, all the fields with the first word capitalized, or some combination? This would determine whether you would do a loop through all the fields, or just convert specific fields.

To make the field contents all lower case, use

$in{'field'} = lc($in{'field'});

To make the first letter upper case and the rest lower case, use

$in{'field'} ~= s/(\w+)/\u\L$1/g;

At least that's what the Perl Cookbook says.



------------------
JPD
Quote Reply
Re: Control on LOWER CASES In reply to
But where do i put this code ?

Parsifal
Quote Reply
Re: Control on LOWER CASES In reply to
Put it in sub add_record in db.cgi, just after the call to &validate_record.


------------------
JPD
Quote Reply
Re: Control on LOWER CASES In reply to
Sorry 'bout that. I must have typed it wrong. Yes, that's the other way to go.

I am familiar with the website. It's just easier for me to look at a book than to open another browser when I'm responding to messages.

I'm sure it's possible to make the first character after a puncuation mark upper case. I don't know how to do it, though.

------------------
JPD


[This message has been edited by JPDeni (edited February 17, 1999).]
Quote Reply
Re: Control on LOWER CASES In reply to
Hello JPDENI !

Your expression :
$in{'field'} ~= s/(\w+)/\u\L$1/g;

leads to a server error.

But i found this :
$in{'field'} = ucfirst(lc($in{'field'}));

It makes the first character of the field in upper case, and the others in lower case.

I am not a Perl programmer, but i guess it must be possible to write a code which would do :
Each time we have ". " (punctuation mark + space), the next character is in upper case. Am I wrong ?

I don't have the book you refer to, but this url :
http://reference.perl.com/guides/perl5.html

Parsifal
Quote Reply
Re: Control on LOWER CASES In reply to
Might want to turn to the Perl FAQ here:

http://language.perl.com/...italize_all_the_word

Cheers,

Alex
Quote Reply
Re: Control on LOWER CASES In reply to
Thank you Alex for this url.

I went there, and tried, but it failed....
In fact, very strange results.
I made a copy&paste of this string (changing $string to $rec{myfield}:
$string =~ /([\w']+)/\u\L$1/g;
and i had a servor error.

Then, more funny, i tried this:
$string =~ s/ (
(^\w) #at the beginning of the line
| # or
(\s\w) #preceded by whitespace
)
/\U$1/xg;

and it changed all letters into numbers....(but not their ASCII value), i don't know what it did....

Well, for another time, maybe..

Parsifal