0

I am using Zend Frameworks Validation feature and am having trouble getting the Regex validator to work.

array(
    'name' => 'Regex',
    'options' => array(
        'pattern' => '[0-9a-zA-Z\s\'\.;\-]+',
            'messages' => array(
            \Zend\Validator\Regex::INVALID_CHARACTERS => "Invalid characters in address"
        )
    ),
)

I have various strings that need to accept letters, numbers, spaces and various characters, and I am using the code above for the various fields.

I've been reading framework.zend.com which doesn't give much detail.

My question is: Am I doing it correctly? Is this how to use regex validator with Zend? Any better examples of this floating around the web?

Thanks guys...

1 Answer 1

2

Replace your pattern with:

'pattern' => '/[0-9a-zA-Z\s\'.;-]+/'

notices:

A regex pattern must be delimited. Here i have choosen / as delimiter, but you can use #, ~, @, |, `, ...

You don't have to escape special character as ., $, |, inside a character class. ; is not a special character and doesn't need to be escaped inside or outside a character class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.