WordPress.org

Ready to get started?Download WordPress

Forums

Participants Database
[resolved] Can I do regex but not have required? (5 posts)

  1. rwilki
    Member
    Posted 7 months ago #

    This is by far one of the best plugins in the repository! I have a question about the signup form and regex. I'm using regex for a few fields to mandate the proper formatting of data. But, on a few of them, I don't want them to be required. Is there a way to accomplish this?

    This is the regex I'm using for example: #^(\d{3}-\d{3}-\d{4})*$#i

    Thanks,
    Bob

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

  2. rwilki
    Member
    Posted 7 months ago #

    I don't know if it's the update or not but the regex is now throwing php errors when filled out incorrectly...

    Warning: preg_match() [function.preg-match]: Empty regular expression in /home/gfriends/public_html/413beta-kenz/wp-content/plugins/participants-database/classes/PDb_FormValidation.class.php on line 188

    my other regex statements seem to be ok.

    I tried #(^(\d{3}-\d{3}-\d{4})*$)?#i but that didn't work either.

    Thanks,
    Bob

  3. xnau
    Member
    Plugin Author

    Posted 7 months ago #

    Well, if you mean by "didn't work" that any input would validate, that's what would be expected from your regex because the whole thing is made optional with that last ?

  4. xnau
    Member
    Plugin Author

    Posted 7 months ago #

    If I understand you correctly, what you want is either nothing or if there is something, it must conform to that pattern. The plugin validation can't work like that, it either validates the input or it doesn't, and as in your example above, regex can do optional portions of a matching pattern, but if the whole pattern is optional, it ends up being a pattern that always returns true.

    What you want to do is implement a custom validation, which can be done by writing a script that adds a new type of validation. The plugin offers API hooks for that kind of thing.

  5. rwilki
    Member
    Posted 7 months ago #

    OK thanks for the explanation. I'll see what I can figure out...

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.