Re: regular expressions question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The + requires at least one character.

The * is "0 or more" characters.

http://php.net/pcre

On Wed, March 5, 2008 9:13 am, It Maq wrote:
> Hi,
>
> I am using that right now and i have don't know how to include blank
> fields. For example if a user does not fill a field in a form i want
> to accept it. I tried the code you posted, for now it is blocking
> blank fields.
>
> Thank you
>
> ----- Original Message ----
> From: Richard Lynch <ceo@xxxxxxxxx>
> To: Adil Drissi <adil.drissi@xxxxxxxxx>
> Cc: php-general@xxxxxxxxxxxxx
> Sent: Tuesday, March 4, 2008 3:09:09 PM
> Subject: Re:  regular expressions question
>
> On Tue, March 4, 2008 1:19 pm, Adil Drissi wrote:
>> Is there any way to limit the user to a set of characters for
>> example
>> say i want my user to enter any character between a and z (case
>> insensitive). And if the user enters just one letter not belonging
>> to
>> [a-z], this will not be accepted.
>>
>> I tried  eregi('[a-z]', $fname) but this allows the user to enter
>> abdg4512kdkdk for example.
>
> What you tried only requires ONE a-z character somewhere in the input.
>
> Try this:
>
> preg_match('^[a-z]+$', $fname);
>
> This will:
> ^ "anchor" the string at the beginning
> [a-z]+ a to z, with at least one letter
> $ "anchor" the string at the end
>
> Note, however, that some people have other characters in their first
> name, such as apostrophe, space, and dash.
>
> Oh, and the digit 3, for "bo3b" who was a programmer on the first
> Apple Macintosh.  His parents were hippies, and that really is his
> name...
>
> You may want to obtain a LARGE list of "first names" and run them
> through your validator as a test.
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/from/lynch
> Yeah, I get a buck. So?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
>
>
>       ____________________________________________________________________________________
> Never miss a thing.  Make Yahoo your home page.
> http://www.yahoo.com/r/hs


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux