I wanted to know how I can specify character count for my regex. I have the correct regex, I only need to make sure this will work validating zero to fourty characters.
here is the regex
$fnameRegex = "/^[a-zA-Z0-9{0,40}-_]+$/";
i might have put the {0,40}
in the wrong place.
Try
$fnameRegex = "/^[a-zA-Z0-9\-_]{0,40}$/";
Everything in a character class []
will only match one character. You put the quantity limiter outside it (you previously had +
which is 1 or more - replace it with {0, 40} which is between 0 and 40).
Also I escaped your -
character in your character class, or else it will be interpreted as a range.
I also recommend to you the great regexr website which is good for interactively playing around with regex.
try [a-zA-Z0-9]{40} this will check 40 characters of alpha numeric with upper and lower case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With