in reply to Need help with regexes to validate user input
but you probably want to allow certain other characters such as - (my name has one) or . (e.g. Sammy Davis Jr.).if ($name =~ /^[a-z]+$/i) { print "only alphas" }
Alternatively, instead of matching the whole string as a sequence of alphabetic characters, look for any non-alphabetic characters:
I would tend to use a regex for the name matching (so that I could specify that the first character be a letter, not a . or - or whatever else I ended up allowing) but for the other two problems, use index and length, respectively. They do have fairly simple regex solutions, though.if ($name !~ /[^a-z]/i) { print "no non-alphas" }
|
|---|