I have a validator that is supposed to ensure that the input string has no
character other than case-insensitive a-z, or accented characters like
e-acute, or space.

It returns false when you pass it "josé" by submitting an HTML form to my
controller action with a browser, but  when you test it against same string
'josé' in a command line script, it returns true. I have tested with Opera
9.26 and Firefox 2.0.0.12 on a Fedora 7 system.

It might be worth noting that I have used the same regex in other web
environments, and it has worked.

When I echo back the form input to the browser I see that  josé becomes
josÃ(c) so I am guessing we have a charset issue. Any tips as to how to fix
it? Thanks!

class Model_Validator_FirstName extends Zend_Validate_Abstract {

    const INVALID_CHARACTERS = 'invalidCharacters';

    protected $pattern = "/[^a-zA-Z\xC0-\xFF ]/";

    protected $_messageTemplates = array(
        'invalidCharacters' => 'Firstname contains illegal characters'
    );

    function isValid($name) {

        if (preg_match($this->pattern,$name)) {
            $this->_error(self::INVALID_CHARACTERS);
            return false;
        }
        return true;
    }
}

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness

Reply via email to