Regular Expression Validation...how to use.

Hey there, Under Custom Fields, field type, there is Regular Expression Validation I've tried entering http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)? which Dr. Google suggested would work to require a valid url. But it doesn't require anything special at all when I'm adding a new post under this custom field. am I missing the point...good possibility. If so, please help me to understand what this is intended for.

Thanks,

Ann

  • Arnold

    You have to keep in mind the syntax for a reqular expression depending on the language used to interpret it. For client side validation (javascript) a regex pattern is delimited with "/" characters. So you have to escape any literal "/" characters.

    So your expression above would have to be changed from

    http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

    to

    http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?

    Also be aware that breaking a regular expression tends to kill all the validation javascript so an error would also prevent Required fields etc from working on other fields. So test field by field adding one at a time so you don't waste time trying to debug a field that's failing because another field is broken

  • aecnu

    Greetings Ann,

    We have not heard back from you as to the status of this issue.

    If you are still having an issue please let us know so that we may try to get you fixed up as soon as possible by choosing to check mark this ticket as unresolved below and posting any new errors or symptoms you are noticing.

    This action will also bring your ticket up front back in plain view again within the ticket system.

    Thank you for being a WPMU DEV Community Member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.