Hi, new to Perl. Learning regular expressions. Im trying to validate a form field using regular expressions. Field criteria is:
- Begin with a letter
- 4-8 characters long
- must include at least 1 digit
So far Ive got:
$fieldValid=$username=~/^\D\w{3,7}\d+/;
I read this as "beginning with any non-digit [^0-9], containing between 3 and 7 alphanumeric characters and having one or more of the previous character which is any digit"
I dont understand it, but \w{3,7} seems to satisfy having 4-8 alphanumeric long?
The following test usernames fall over:
a1bcdefg
ab1cdefg
abc1defg
The following are accepted:
abcd1efg
abcd1efg
abcdef1g
abcdefg1
So the location of the digit seems to be a factor, but not sure why.