in reply to Re: String validation
in thread String validation

Let's make it a little more readable, then:
if ($string =~ m!^(\w{4})$!) { $string =~ tr/[a-z]/[A-Z]/; # or $string = uc $string; # do something } else { # do some error }
Since the OP wants four alphanumerics (and they are merely *likely* to arrive in lowercase), we'll use \w.

The reason I suggested using tr/// instead of uc is that, in my testing, uc() failed on a scalar starting with a digit. Now it seems to work correctly. Let's go back to:

if ($string =~ s!^(\w{4})$!uc($1)!e) { # do something } else { # do some error # print "Location: $error_url" }

Replies are listed 'Best First'.
RE: You're right...
by btrott (Parson) on Mar 25, 2000 at 02:36 UTC
    Do you mean \w? \d just matches digits. I thought of using \w, but \w is alphanumerics plus '_', and I didn't know if the OP wanted '_'.