fuel/core — Issue #555: 'valid_string' Not Working in ORM\Model
Author: knudpotente
Created: 2011-10-09 04:25:29+00:00
State: open

Issue as reported on the Forum (http://fuelphp.com/forums/topics/view/5217).

Validation using 'valid_string' does not behave as expected when defined inside ORM\Model $_properties. Example: we want to establish validation for a 'surname' field in the model, where we will only accept alpha characters, spaces and dashes. This is defined in the model as:

```php
array(
'type' => 'string',
'label' => 'Surname',
'validation' => array(
'trim',
'strip_tags',
'required',
'valid_string'=>array('alpha','spaces','dashes')
),
),
);

protected static $_observers = array(
'Orm\Observer_CreatedAt' => array('before_insert'),
'Orm\Observer_UpdatedAt' => array('before_save'),
'Orm\Observer_Validation' => array('before_save'),
);

}
```
The way the 'valid_string' validation in the surname field behaves - using different configurations - is like this:

(1) Using 'valid_string' => array('alpha') only: works as expected - allows only alpha characters, fails if anything else is typed.

(2) Using 'valid_string' => array('alpha', 'whatever'): if anything else is added *after* 'alpha' (such as 'spaces', or 'dashes'), then it ignores whatever has been added, and validation works exactly as in (1) - that is, if I add a space or a dash, even if I specified that this is be allowed by using 'spaces' or 'dashes', then validation fails

(3) Using 'valid_string' => array('whatever','alpha'): if anything is added *before* 'alpha', then validation *always* fails, even if the field contains only alpha characters.