WordPress.org

Forums

Fast Secure Contact Form
[resolved] Help to force MM/YYYY with regex (3 posts)

  1. nermal.newmail
    Member
    Posted 1 year ago #

    Hi all,

    I am implementing Fast Secure Contact Form to collect registration forms for a conference. I have included a membership expiration date field, and want registrants to be able to input ONLY MM/YYYY (that exact format, with slash, and that number of digits. This way, when exported to our database the formatting is consistent).

    I wrote the following regex to accomplish this, with the intention of adding it to the 'validation regex' field:

    /^([0-1][0-9][/][2][0][1-2][0-9])$/

    When I test this regex in an external validator, it works fine, accepting and only accepting the desired date format. But it does not work in the form, and returns the fail message upon form submission. I am implementing several other expressions elsewhere in the form (limiting fields to digits only, etc) which are working properly.

    Any ideas on what I am doing wrong? If we can't force the desired format it's not the end of the world, but it will save my colleague a lot of time in reformatting our database later. I'm a newbie so perhaps the solution is glaringly obvious. I would appreciate any assistance. Many thanks!

    http://wordpress.org/plugins/si-contact-form/

  2. Mike Challis
    Member
    Plugin Author

    Posted 1 year ago #

    Escape the slash to avoid clash with the beginning and end slashes
    /^([0-1][0-9][\/][2][0][1-2][0-9])$/

  3. nermal.newmail
    Member
    Posted 1 year ago #

    Thanks, worked perfectly! Figured it was something small...

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Fast Secure Contact Form
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic