WordPress.org

Ready to get started?Download WordPress

Forums

Participants Database
[resolved] Regex Matches (5 posts)

  1. rwilki
    Member
    Posted 1 year ago #

    Love your particpants database plugin but I can't get regex matches to work. I've tried a million expressions and they're just not working.

    looking for us phone number exp. preferably mandating format like this: xxx-xxx-xxxx

    and us zip code with or without -xxxx

    Thanks,
    Bob

    http://wordpress.org/extend/plugins/participants-database/

  2. rwilki
    Member
    Posted 1 year ago #

    Never mind, I figured it out...

    ^(\d{3}-\d{3}-\d{4})*$ <!-- phone -->
    ^\d{5}(-\d{4})?$ <!-- zip -->

    Great plugin...

  3. xnau
    Member
    Plugin Author

    Posted 1 year ago #

    Bob,

    Regexes can be tricky, I know. It's important to remember that the statement must include delimiters to work, that's the most common mistake. You could try something like this for your phone number:

    /^\d{3}-\d{3}-\d{4}$/

    to strictly force your format. Be sure to tell your users what you're expecting, the help field is good for that. The delimiter, if you don't know, is the first and last character of the regex and should be something that is not in the regex statement itself, as in the example above.

    Your second example is slightly more tricky...you could try:

    /^\d{5}(-\d{4})?$/

    for that.

  4. rwilki
    Member
    Posted 1 year ago #

    I figured it out if you look above. I didn't include the "#" in the examples, but I think that was the difference maker.

    Thanks again!

  5. xnau
    Member
    Plugin Author

    Posted 1 year ago #

    Glad you got it sorted.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags