Validation on alphabetic character

For programming and general questions on Zend Framework

Validation on alphabetic character

Postby quantro on Thu May 07, 2009 11:59 am

i read this line in the zend framework programmer references guide :
Alpha
Returns true if and only if $value contains only alphabetic characters. This validator includes an option to also consider white space characters as valid.

I try to use that, but if i use white space as input, it reject and shows error. then i realize that the references contain this line :
This validator includes an option to also consider white space characters as valid.
the question is, how to use the option??
can someone show me the way??
quantro
 
Posts: 6
Joined: Tue Apr 28, 2009 7:07 am

Re: Validation on alphabetic character

Postby ericritchie on Thu May 07, 2009 1:43 pm

Hi Quantro,

Just pass "true" to the constructor of Alpha filter e.g.:

Code: Select all
$filterChain->addFilter(new Zend_Filter_Alpha(true));


Regards,
Eric Ritchie.
User avatar
ericritchie
 
Posts: 119
Joined: Tue Feb 10, 2009 10:09 am

Re: Validation on alphabetic character

Postby quantro on Fri May 08, 2009 2:36 am

Code: Select all
$this->addElement('text', 'element1', array(
            'label'      => 'element1:',
            'required'   => true,
            'validators' => array(
                array('validator' => 'StringLength', 'options' => array(0, 20))
                )
        ));

that's my code, ho to add that filter?? or can i add it as validator??
quantro
 
Posts: 6
Joined: Tue Apr 28, 2009 7:07 am

Re: Validation on alphabetic character

Postby quantro on Fri May 08, 2009 3:21 am

Code: Select all
'validators' => array(
                array('validator' => 'StringLength', 'options' => array(0, 20)),
                array('validator' => 'Alpha', 'options' => true)
                )


thanks, it solved..
quantro
 
Posts: 6
Joined: Tue Apr 28, 2009 7:07 am


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 6 guests