Jump to content


Photo

eregi() chokes on (?= lookahead


  • Please log in to reply
2 replies to this topic

#1 david.marks

david.marks
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 July 2006 - 05:35 PM

I am trying to employ a common regex for password verification in PHP 5.0.5. 

The goal is to simply reject passwords that don't meet the length requirement of 8-25 characters, and that don't have at least one each of numbers, upper case and lower case letters.

I grabbed this example from a regex reference site:
("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,25}$

My code looks like this:

if (!eregi("^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,25}$",$password) {//do something}

This gives me the following error:
"Warning: eregi() [function.eregi]: REG_BADRPT..."

The problem seems to be with the ?= lookahead operator.  All references suggest this is valid code, but PHP seems to choke on it.  Other regex seem to work fine, so I'm at a loss.

Can any experts offer any ideas?  Thanks in advance.

- David Marks


#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 19 July 2006 - 06:46 PM

You must use preg_* functions in order to use lookarounds.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 david.marks

david.marks
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 July 2006 - 07:31 PM

Excellent!  Thank you for the prompt reply.

I haven't needed preg_ functions until now.  I stumbled around there for a while until I figured out that the expression needed proper delimiters.  I am up and running now.

Thanks again!!  I'd still be lost without your assistance.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users