in reply to String validation
This looks for the start of a string, exactly four characters from the class between lowercase a and lowercase z or between 0 and 9 inclusive, storing them, and then the end of the string.if ($string =~ m!(^[a-z0-9]{4})$!) { $string =~ tr/[a-z]/[A-Z]/; # do something } else { # do some error }
If found, it uppercases it. (I use tr/// because it's faster than a substitution, and because leading digits may cause a warning about modifying a constant. uc is another option.)
|
|---|