Gossamer Forum
Home : General : Perl Programming :

Stop ALL CAPITALS

Quote Reply
Stop ALL CAPITALS
I've spotted several threads about limiting filed input to all lower case (or allowing just the first letter as upper case).

In certain fields, I need to allow for a name (so I might expect half a dozen upper case letters) but I'd like to stop a user entering all capitals. Is there a piece of code I can add which rejects input which is all caps?

TIA,

Andy
Quote Reply
Re: Stop ALL CAPITALS In reply to
If you know the regular expresions I think they will help you much.
For example, un Perl, using the reg-exps, you can know if there is at least ONE not capital letter with:

$text = <STDIN>;
if ( $text =~ /[a-z]/g ) {
print "OK!\n";
}else{
print "NO!\n";
}

...but this isn't very useful because you can get an entry like 'HELLO WoRLD' and it will be ok.

Regular expresions are very powerful, but I'm only a beginner in Perl & reg-exps so I can't tell you a magic recipe Smile But if anyone knows it, I'm interested also Smile

Here will check if there are at least 2 capital letters together.
if ( <STDIN> =~ /[A-Z]{2}/g ) {
print "NO!";
}else{
print "OK!";
}
...but it will accept HeLlO WoRlD Smile

[This message has been edited by Paradox (edited November 04, 1999).]
Quote Reply
Re: Stop ALL CAPITALS In reply to
If you want to allow them to make the first letter uppercase but the rest non you could try something like this: (this will allow you to parse through multiple words in strings as you go)

foreach (split(/ /, $your_text_field) {
&do_failed if (substr($_, 1) =~ /[A-Z]/));
}

It skips the first letter of each word and sends them to the do_failed subroutine if any other letters are capitol.
- Gordon --


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);
Quote Reply
Re: Stop ALL CAPITALS In reply to
And if they are only entering one word (no spaces), and you want to force first letter uppercase, and the rest lower, something like:

$text = ucfirst lc <STDIN>;

will do Smile

For multiple words, a combination of split, parse as above, and join would work too.

--mark

------------------
Due to repeated requests for support via ICQ, I am once again offering support online.

The ONLY number I will accept requests on is #53788453. Messages sent to my other numbers will not pass through to me, as I have security settings set to ignore messages from users not on that list.

I don't know how often I will be active on this number, as it is for only when I am free to offer assistance.

Could this signature be any longer? :)
Quote Reply
Re: Stop ALL CAPITALS In reply to
Good stuff Smile
just be careful tho, if one or more of these fields is case sensitive you don't want to alter their data. For instance, if they were submitting what they wanted their password to be as :
asG43P

it would get converted to
Asg43p
Just a thought
-- Gordon --


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);