Syntax for preg validations

cokenour

New Member
Does this look ok for a preg validation of US zip code?

Code:
('/^[0-9]{5}([- ]?[0-9]{4})?$/', $string)

I'm using a regex cookbook and forums to figure this out and I don't know if the syntax is off. It seems to catch wrong entries, but it also seems to be keeping valid entries from submitting too. This is the case with several validations I'm using (US zip, US phone, email etc).

Thoughts?
 
Yup, that's the right regex, to get either '12345', '12345 1234' or '12345-1234'.

Are you doing this with a standard new validation rule? And if so, I assume you aren't including the surrounding stuff ($string, parens)?

-- hugh
 
I think so. I went into "Validation Rules" and created a new rule. Then I opened the element I wanted use with it, and I added the newly created rule.

I've since removed the rules from the elements because it's a production site (I don't use a local host, I upload/view). I'll create a test form so that we can break some stuff and hopefully narrow it down. I'll post the link once it's up.
 
Hello

what exactly did you enter for each of the validation rule settings?
 
Here's a snapshot of the validations:

fabrik.bmp
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top