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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP ereg syntax problem 1

Status
Not open for further replies.

ShugNiggurath

Technical User
Jul 6, 2007
5
0
0
GB
Hi,

I have the following code:

Code:
		if (!ereg('^[a-z_]$', '$sec')) {
		// failed url validation
		echo "You are not allowed to access this page in that way";
		} else {

$sec is a variable passed in the URL that I want to make sure is only lowercase letters or underscore, the above code fails any variable passed in the URL whether valid or not, and if I take out the !NOT operator, the reverse happens.

I've also tried the following versions:

Code:
		if (!ereg('^[a-z_]+$', '$sec')) {
		// failed url validation
		echo "You are not allowed to access this page in that way";
		} else {	


		if (!ereg('[a-z_]', '$sec')) {
		// failed url validation
		echo "You are not allowed to access this page in that way";
		} else {

and also without the underscores while testing.

I just can't see what I'm doing wrong. A pint in it for anyone who can help!

Cheers in advance,

Hugh
 
Thank you Feherke, it's a doddle when you spot it. I've been toying with the pattern that long I don't even think I was looking at the string.

Wood for trees!

Cheers

H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top