I’ve never been the best at creating regex statements, so I stumbled upon this one in a forum. This regex seems to work when validating email addresses (or web site addresses) if you’re using FS Contact Form for WordPress:
/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/
Just paste the above into the “Validation Regex” field and click “Update Options.” Here’s what mine looks like (click image for a larger version):
NOTE: This regex should work for any PHP-based validating that you’re doing (even if you’re not using WordPress with FS Contact Form).
UPDATE: Silly of me not to have noticed this before, but there’s already a built-in email validation option in FS Contact Form. Just select “email” from the drop-down and you’re good to go (click for a larger image):
Wow, thanks for posting this even though you found the easy answer.
I want to use a Validation REGex to make a simple human test.
For example, I want a field that says: what is 5+5? I want the form to display an error message if the answer is anything other than 10.
So, would I just enter 10 in the REGex field? I appreciate any answer.
Hi Joanne,
You could do something like this:
var match = /^10$/;
There’s a cool site that lets you test regex online, too. It’s called regexplanet: http://www.regexplanet.com/simple/index.html
Paste ^10$ into the Regular expression field, then a few different answers into the input field (things like “10″, “101″, “1000″ … that regex should only match “10″).
Good luck!