Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hi,

I'm trying to create a simple contact form. In the fname/lname fields, the requirements are that alphas, hypens, undescores, and apostrophes are allowed. I'm trying to use the built in regex validator option to accomplish this. The code is as follows:

Code: Select all
 <cms:input name="lname" type="text" maxlength="100" id="lname_input" title="Enter Last Name; upper & lower case, hypen, and apostrophe only" validator="regex=/^[A-Za-z_'-]+$/" validator_msg="Must enter a valid last name" required="1" />


Everything EXCEPT apostrophes work fine. I've tested the regex on a builder site and all the characters are matching properly there, including the apostrophes. When the form submits, the apostrophe gets changed to its HTML character respresentation when the page refreshes. I'm thinking this is what's getting run through the validator and that's why it's not working. Do couch forms automatically change special characters?

Is there a decent workaround? I've thought about just manually doing a preg_match(), but it'd be nice to keep it simple and use the built in features.

Thanks
Hi,

Yes, you are correct - Couch 'sanitizes' certain special characters (e.g.quotes, double-quotes, angle brackets) by converting them to their HTML entity codes.

I think the following regex should cover the 'sanitized' apostrophe (either '&#039;' or '&apos;') -
Code: Select all
<cms:input name="lname" type="text" maxlength="100" id="lname_input" title="Enter Last Name; upper & lower case, hypen, and apostrophe only" 
validator="regex=/^(?:&#039;|&apos;|[A-Za-z_-])+$/"
separator='%'
validator_msg="Must enter a valid last name" required="1" />

Please note that we also had to use the 'separator' param because the regex had a 'pipe' which carries special significance for the tag.

Hope this helps. Do let me know.
Thank you so much, I had landed on this approach (opening up the regex to allow for html representations of the apostrophe) but my regex didn't work quite as well as yours. Thanks for the help :)
3 posts Page 1 of 1