Support » Plugins and Hacks » [Resolved] Can I do regex but not have required?

[Resolved] Can I do regex but not have required?

  • 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



Viewing 4 replies - 1 through 4 (of 4 total)
  • 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.


    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 ?

    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.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Can I do regex but not have required?’ is closed to new replies.