Gossamer Forum
Home : General : Perl Programming :

Stupid Regex Question...

Quote Reply
Stupid Regex Question...
Ok, i never said I was good with regex, but theoretically this SHOULD work, but it doesn't...lol.

Code:
if(!preg_match("/[a-zA-Z]{2,15}+\s{1,2}+[a-zA-Z]{2,25}+$/", $name))
{
error("The name you provided not appear to be valied. Please note it needs to be your FULL name. Please try again...");
}

The error code returned is;

Quote:
Warning: Compilation failed: nothing to repeat at offset 14 in c:\program files\nusphere\apache\nsdocs\test\wedding\add.php on line 212

Anyone got an idea on why this is? I'm trying to search for 2-15 characters for the first name, then no more than 2 spaces, and then 2-25 charahters for the last name. For some reason it doesn't like the formatting (if I remove the {...} parts it works ok).

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: [AndyNewby] Stupid Regex Question... In reply to
If you are using {2,15} and {1,2} and {2,25} then why do you also have + Wink

How about:

if(!preg_match("/^[a-z]+\s[a-z]+$/i", $name))

I assume you can use "i" like in perl?

Last edited by:

RedRum: Mar 9, 2002, 6:26 AM
Quote Reply
Re: [RedRum] Stupid Regex Question... In reply to
Incase their name is something like 'John Paul Simpson' Wink Lots of people have 3 word long names.

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: [AndyNewby] Stupid Regex Question... In reply to
Yeah but the point I am making is that using + the way you used it is wrong.

Last edited by:

RedRum: Mar 9, 2002, 6:42 AM
Quote Reply
Re: [RedRum] Stupid Regex Question... In reply to
MM, that example works for 2 words, but I really need to acommidate for people with longer names. Any more ideas?

Thanks for your help so far Smile

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: [RedRum] Stupid Regex Question... In reply to
Never mind, I got it working with;

if(!preg_match("/^[a-zA-Z]{2,15}\s{1,2}[a-zA-Z]{2,25}\s{0,2}[a-zA-Z]{0,20}$/i", $name))

Wink

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: [AndyNewby] Stupid Regex Question... In reply to
Hmm either remove the i or all the A-Z's
Quote Reply
Re: [RedRum] Stupid Regex Question... In reply to
Whoops..forgot that was there...lol.

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!