Gossamer Forum
Quote Reply
Regex...
Before anyone has a go at me, I put this in here because its a PHP post...

I'm having problems with getting spaces to be recognised in my string as ok. At the moment I have;

------
if (!preg_match("/([0-9a-z]\s){1,$max_title_length}$/i",$Price)) { error("Your advert title was incorrect. It must be between 1 and $max_title_length."); }
------

$max_title_length is provided as 255 in the config file, and I know it is correct as it shows 255 ok in the error. Does anyone know how to include the space in there, but still limit the sentance to 255 chars?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Regex... In reply to
If php regex is anything like perl (which I guess it is as it was "copied")... then your syntax is wrong.

Code:
if (!preg_match("/([0-9a-z ]{1,$max_title_length})$/i",$Price)) {

I'm not sure why you need ( ) though seeing as you aren't doing anything with the match.

Last edited by:

Paul: Jul 11, 2002, 9:32 AM
Quote Reply
Re: [Paul] Regex... In reply to
Yup, its 'Perl Compatable'. That seems to have fixed it...but the {} parts arn't seeming to take effect Crazy

if (!preg_match("/[0-9a-z ]{1,50}$/i",$Title)) { error("Your advert title was incorrect. It must be between 1 and $max_title_length."); }

I even tried manually entering the 50 in, in case it didn't like a variable being called within the match.

Any ideas?

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Regex... In reply to
What do you mean by "it's not taking effect"?

Perhaps you need ^ at the start of your regex? Tongue

Last edited by:

Paul: Jul 11, 2002, 9:57 AM
Quote Reply
Re: [Paul] Regex... In reply to
What I mean, is it doesn't matter if I used 500 charachters in the $Title variable, it just doesn't care!

I use the {,2} option in the price checking;

if (!preg_match("/[0-9]{1,6}\.[0-9]{,2}$/",$Price)) { error("The Price you entered, $Price, was not valid. You need to provide the \$'s and cents (i.e 23.00). Prices are in dollars."); }

And the above works fine Unsure

Thanks

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Regex... In reply to
Your regexs are only matching the end...you need a ^
Quote Reply
Re: [Paul] Regex... In reply to
Sweet...works fine now :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!