Fixed! Thanks to some help I figured out that it was a problem with the
expression. I changed the expression to:
/^[-'A-Za-z]+$/
and it seems to be working.
benxmy wrote:
>
> So I'm still having some failure on this, maybe related to my limited
> understanding of regex in general or perhaps my limited understanding of
> the zend validator regex class.
> If I were to program my own little validator, the following would work
> fine:
>
> if( preg_match("/[^a-z\' -]/i","valid8") )
> return "fail!";
> else
> return "success!";
>
> In my understanding, this would work because it would match the '8' in
> 'valid8'. If the string was 'validate' then nothing would match and it'd
> be considered successful. However, when using the Zend regex validator in
> the way I'm attempting to, I don't really have that flexibility. If I use
> the above regex:
>
> protected $_validators = array(
> 'lname' => array(array('Regex','/[^a-z\' -]/i'))
> );
>
> and try the string 'valid8', the validation will return true because it
> will match the '8'. If I remove the '^' (/[a-z\' -]/i), it will ALSO
> return true, because it will return true as soon as it matches the 'v'.
> I've done quite a bit of digging around looking at both regular
> expressions and Zend's implementation of regexs, but am at a loss. Is
> there a way to get around this that I'm not seeing? Or will I have to
> write my own validator to accomplish this? Thanks a lot for any input!
>
>
>
> Matthew Weier O'Phinney-3 wrote:
>>
>> -- benxmy <[email protected]> wrote
>> (on Thursday, 05 February 2009, 12:20 PM -0800):
>>>
>>> So I figured it out to an extent, but I think I'm still one step off and
>>> I
>>> haven't been able to track down the exact syntax for using regex in this
>>> context. I changed the $_validators array to:
>>>
>>> ****
>>> protected $_validators =
>>> 'lname' => array(array('Regex','/[^a-z\'-]/i'))
>>> );
>>> ****
>>> And it kind of works, except to the opposite! The regex validator will
>>> return false if I have a clean string (because it doesn't actually match
>>> anything) and true if I have a bad character in there (a 7, for
>>> example), so
>>> it validates the wrong way. I assume there's a way to reverse that in
>>> ZF,
>>> but I haven't been able to find the correct syntax. Is that possible?
>>> Or
>>> do I need to alter the expression itself?
>>
>> The expression is matching any value that is *not* alphabetic, a single
>> quote, or a dash. Just omit the '^' in your character class (which is a
>> negate operator), and you should be good.
>>
>>
>>> Matthew Weier O'Phinney-3 wrote:
>>> >
>>> > -- benxmy <[email protected]> wrote
>>> > (on Tuesday, 03 February 2009, 11:27 AM -0800):
>>> >>
>>> >> Still not quite there. I believe I may be using Zend_Filter_Input
>>> >> incorrectly. I made the changes to my $_validators array as
>>> described
>>> >> and
>>> >> now it throws the following exception
>>> >>
>>> >> Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception'
>>> with
>>> >> message 'Plugin by name 1 was not found in the registry.'
>>> >> ...
>>> >> Zend_Loader_PluginLoader->load('1')
>>> >>
>>> >> Just for reference, when I print out the $_validators array that's
>>> passed
>>> >> to
>>> >> my validation function, this is the result:
>>> >>
>>> >> Array ( [field1] => Array ( [0] => Array ( [validator] => 1
>>> >> [breakChainOnFailure] => 1 [options] => Array ( [0] => /[^a-z'-]/i )
>>> ) )
>>> >> )
>>> >
>>> > Okay, I'm sorry -- I misled you. I though you were using Zend_Form,
>>> > which has a slightly different notation.
>>> >
>>> > I'll review the thread later and see if I can diagnoes further.
>>> >
>>> >> So it looks as if it's taking the 'true' in either the validator
>>> value or
>>> >> the breakchainonfailure value of the array and trying to load it.
>>> I've
>>> >> tried to script it in a few different ways and triple-checked that I
>>> have
>>> >> the $_validators array set up correctly (testing with only the single
>>> >> field)
>>> >> and get the same exception.
>>> >>
>>> >>
>>> >>
>>> >> Matthew Weier O'Phinney-3 wrote:
>>> >> >
>>> >> > -- benxmy <[email protected]> wrote
>>> >> > (on Monday, 02 February 2009, 01:58 PM -0800):
>>> >> >
>>> >> > You're creating the validators array incorrectly. I'm assuming
>>> from
>>> >> > your example that you're creating an array of field => validators
>>> >> arrays
>>> >> > that you use to create your elements. The problem with how you've
>>> done
>>> >> > it is that setValidators(), which is called when you pass
>>> validators
>>> >> via
>>> >> > the constructor, expects that each element in the array is either a
>>> >> > string or an array representing a single validator. Additionally,
>>> you
>>> >> > can sometimes run into issues with order of operators, so I
>>> typically
>>> >> > recommend using key/value pairs in each array defining a validator.
>>> >> >
>>> >> > Try the following:
>>> >> >
>>> >> > protected $_validators = array(
>>> >> > 'field1' => array(
>>> >> > array(
>>> >> > 'validator' => true,
>>> >> > 'breakChainOnFailure' => true,
>>> >> > 'options' => array('/[^a-z\' -]/i'),
>>> >> > ),
>>> >> > ),
>>> >> > );
>>> >> >
>>> >> >
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://www.nabble.com/getMessages%28%29-crashes-with-quotes%21-tp21793751p21817057.html
>>> >> Sent from the Zend Framework mailing list archive at Nabble.com.
>>> >>
>>> >
>>> > --
>>> > Matthew Weier O'Phinney
>>> > Software Architect | [email protected]
>>> > Zend Framework | http://framework.zend.com/
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/getMessages%28%29-crashes-with-quotes%21-tp21793751p21860299.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>
>> --
>> Matthew Weier O'Phinney
>> Software Architect | [email protected]
>> Zend Framework | http://framework.zend.com/
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/getMessages%28%29-crashes-with-quotes%21-tp21793751p22014614.html
Sent from the Zend Framework mailing list archive at Nabble.com.