Re: Regular Expressions
| From: | Jochem Maas | Date: | Tue, 22 May 2007 18:26:16 +0000 |
| Subject: | Re: Regular Expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255341@lists.php.net to get a copy of this message | ||
Don Don wrote:
> Hi all, am trying to run a regular expression to a list of user entered data on some forms.
>
> I've creating what i think is a matching pattern for each category as shown below:
>
> function validateEntry($regularExpression, $fieldValue)
> {
> if(preg_match($regularExpression, $fieldValue))
> {
> return "true";
> }
> else
> {
> return "false";
> }
> }
>
this function sucks - it does nothing more than wrap preg_match and
returns strings instead of boolean values.
regexp's become hard very quickly - but for simple checks like your
doing your probably better off using the functions in the ctype
extension:
http://php.net/ctype
> i made a list of rules that are passed into the function above
>
> 1) [a-zA-Z][0-9] //allow any characters and numbers together anywhere within the text
> 2) [a-zA-Z] //allow only any charaters in the text
> 3) [0-9]{2} //allow only digits and they must be 2 in length
> 4) [a-zA-Z]{1} //allow only 1 character either uppercase or lowercase
>
>
> but each of these fail the validation when data is entered appropriately , seems iam getting
> something wrong.
how exactly do you define these regexps? seems like your forgetting to add a start/end delimiting
character to the regexp strings (as others have pointed out).
>
>
> Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and
> lay it on
> us.http://us.rd.yahoo.com/evt=48516/*http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
> hot CTA = Join Yahoo!'s user panel