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

eregi problem (again) :(

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Does anyone know why this regex always proves that $_description is over 100 charachters, even when it isn't? :-/

if(!eregi("[\w\d\s\.,]{,100}", $_description))

I only want words, digits, commands as full stops to be allowed in this variable.

Cheers in advance.

Andy
 
strlen won't validate that specifically will it?

I would suggest using the positive instead of the negative and maybe something like...

if (eregi("^[\w\s\d,.]{100,100}[\w\s\d,.]*")) {
is 100 or more acceptable characters
}

I'm sure I got something wrong in there, I'll check it tomorrow when I have a test machine... but the idea is

anchor it to the beginning... find at least 100 acceptable characters, then find any number of acceptable characters after that.

Your way, I'm not sure why you were having your problem, but... you could also have just 100 characters in the middle surrounded by garbage or some such.

-Rob
 
youradds,
[tt]{,100}[/tt] means that as long as the first 100 hundred characters (or less) are any of the characters specified. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top