On Jul 23, Stephanie Stiavetti said:
>I need to make sure that a field contains ONLY letters... and this is the
>regular expression I'm using:
>
>$name=~/^[a-zA-Z]+/
That doesn't check to make sure the string ONLY has those. It checks to
see whether it STARTS with them.
>what am I doing wrong? also, will said regular expression accept foreign
>characters as letters, like an umlaut? (ö)
In order to allow locale-specific characters, you must the \w char. class
abbreviation:
if ($name =~ /^\w+$/) {
# valid
}
However, that includes 0-9 and _ as well. To exclude those requires a bit
of shenanigans:
if ($name =~ /^[^\W0-9_]+$/) {
# valid
}
Hopefully, in Perl 5.8 or Perl 6, there will be a much simpler character
class subtraction syntax:
if ($name =~ /^[\w&&[^0-9_]]+$/) {
# valid
}
which reads "\w AND NOT 0-9_".
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]