On Sun, Mar 9, 2008 at 12:31 PM, Deane <[EMAIL PROTECTED]> wrote:
>
>  This may be more of a regex question, but I can't seem to get some
>  validation working inside Cake that seems to work fine outside of
>  Cake.
>
>  A field needs to either be (1) a valid number, or (2) nothing.  So, in
>  effect, "You don't have to enter this, but if you do, it better be a
>  number."
>
>  This...
>
>  /[0-9]+|/
>
>  ...doesn't work.  To me, that regex says, "Any sequence of numeric
>  values, or the empty string."
>
>  What does it say to you?

One--not zero--or more digits. Try /[0-9]?/

>  On the same note, I'm trying to the same thing with a date.  This
>  doesn't work either:
>
>  /([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])|/
>
>  Any ideas?

rule => 'date'

However, your regex can also be made better by:

/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/

or, if you don't require leading zeroes:

/[12][0-9]{3}-0[1-9]|1[012]-0[1-9]|[12][0-9]|3[01]/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to