how to validate given data is alphanumeric or not with zend_validator

php, zend-framework

Solution

I'm using standard Alnum validator for this purpose.

In form definition like this:

$this->addElement('text', 'username', array(
  'label' => 'Uživatelské jméno',
  'required' => true,
  'validators' => array(
      array('Alnum'),
      array('StringLength', false, array(2, 50))
  )
));

In your notation something like following should do the trick:

$this->addValidator('Alnum');

See possible arguments/other standard valiators on on Zend Framework pages

Problem

I have code ``` $this->addValidator('Regex', false, array('/^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/')); ``` which is used to validate if data is alphanumeric or not but its not working, how to do it?

Original source