do you know how one can eliminate something. I am tring to write an expression that has a-z (small), can have numbers, should not have any other chararters and should not start with number ..so far thats what i got
array
(
'regex' => '/[a-z0-9]{1,70}/',
'method' => 'validate_format_of',
'column' => 'name',
'message' => 'Please enter your name'
),
If it has only lower-case letters and can't start with a number, then it must start with a lower-case letter, followed by either lower-case letters or numbers:
'/[a-z][a-z0-9]/'
then make sure it matches the entire string:
'/^[a-z][a-z0-9]$/'
then make sure to limit the length of the string. If the minimum-length string is a single character and the maximum length string 70 characters, you need:
'/^[a-z][a-z0-9]{0,69}$/'
In English, this regular expression is, "Match a string that is, in its entirety, one lower-case letter followed by as many as 69 additional lower-case letters and numerical digits"
^" means "assert beginning of the string"
"$" means "assert end of the string"
If you sandwich the regular expression in these two characters, you effectively tell the regexp engine that the regular expression must match the entire string. Without them:
'/[a-z][a-z0-9]{0,69}/'
the expression would match the string "AZ--[red]a0[/red]CCC" because the looked-for pattern (in red) appears as a substring of the string to match.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.