For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2007 > Newbie needs help with regular expression









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie needs help with regular expression
raj

2007-02-16, 7:59 am

Hi,

Please can someone help regarding providing a regular expression for entering
a set of characters with letters, numbers, periods (.), hyphens (-), or
underscores (_) only.

I've got as far as this:

$pattern="^([_a-z0-9-]+)(\.[_a-z0-9-])$";

Thank you in advance.

Kind regards,

Raj (newbie)

lorento

2007-02-16, 7:59 am

$patterns = "/[^a-z0-9.-_]/i";
if (preg_match ($patterns, $word))
echo "not allowed";
else
echo "allowed";

--
http://ascii.mastervb.net -- ASCII Art Generator
http://anagram.mastervb.net -- Anagram Generator
http://www.mastervb.net/phpbooks/ -- Best PHP MySQL Books

On Feb 16, 5:19 pm, raj <r...@nospam.com> wrote:
> Hi,
>
> Please can someone help regarding providing a regular expression for entering
> a set of characters with letters, numbers, periods (.), hyphens (-), or
> underscores (_) only.
>
> I've got as far as this:
>
> $pattern="^([_a-z0-9-]+)(\.[_a-z0-9-])$";
>
> Thank you in advance.
>
> Kind regards,
>
> Raj (newbie)



raj

2007-02-16, 7:59 am

Hi,

Is there an ereg equivalent please.

Thank you in advance,

Raj

On Fri, 16 Feb 2007 10:35:17 +0000, lorento wrote
(in article <1171622115.950808.192540@p10g2000cwp.googlegroups.com> ):

> $patterns = "/[^a-z0-9.-_]/i";
> if (preg_match ($patterns, $word))
> echo "not allowed";
> else
> echo "allowed";
>
> --
> http://ascii.mastervb.net -- ASCII Art Generator
> http://anagram.mastervb.net -- Anagram Generator
> http://www.mastervb.net/phpbooks/ -- Best PHP MySQL Books
>
> On Feb 16, 5:19 pm, raj <r...@nospam.com> wrote:
>
>



lorento

2007-02-18, 9:57 pm

I think you better use preg because faster than ereg. I heard that
ereg will be deprecated.

--
http://loan.mastervb.net
http://ascii.mastervb.net

On Feb 16, 6:08 pm, raj <r...@nospam.com> wrote:[color=darkred]
> Hi,
>
> Is there an ereg equivalent please.
>
> Thank you in advance,
>
> Raj
>
> On Fri, 16 Feb 2007 10:35:17 +0000, lorento wrote
> (in article <1171622115.950808.192...@p10g2000cwp.googlegroups.com> ):
>
>
>
>
>
>
>
>
>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com