That name solution just checkes to see if there are letters in it, not that there are only letters in it. One regex to test that would be $who =~ /^([a-zA-Z])$/. That would give you the flexibility to later require it to start or end with certain letters, allow a - in the middle or a .
Example of how the two regex differ when matching a string.
use strict; my $test1 = "abcd"; print "Testing: $test1\n"; print "Passed #1\n" if ($test1 =~ /[A-Za-z]/); print "Passed #2\n" if ($test1 =~ /^([A-Za-z])*$/); $test1 = "abcd1234"; print "\nTesting: $test1\n"; print "Passed #1\n" if ($test1 =~ /[A-Za-z]/); print "Passed #2\n" if ($test1 =~ /^([A-Za-z])*$/); # output __DATA__ Testing: abcd Passed #1 Passed #2 Testing: abcd1234 Passed #1
In reply to Re: Re: Audrey Fong
by eric256
in thread Need help with regexes to validate user input
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |