Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex ?

Status
Not open for further replies.

wolf73

Programmer
Feb 12, 2006
93
CA
What are they doing here, are they saying it should be a number between 0-9 and first number should not be 5 and 9?


array
(
'regex' => '/^[0-9]{5,9}$/',
'method' => 'validate_format_of',
'column' => 'zip',
'message' => 'Invalid zip'
),
 
No i thought it would be made between 0-9 but it should not have more than 9 digits and less than 5 digits
 
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"



Want the best answers? Ask the best questions! TANSTAAFL!
 
thanks a lot

'/^[a-z][a-z0-9]$/'

whats is purpose of
/^ and
$/

 
^" 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.

All this is documented in the PHP online manual:


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top