Support » Plugin: Contact Form 7 Phone Module » regular expression validation not working

  • Resolved Shashank Shekhar


    Hello I am using CF7 Phone Module 2.0 with wp 3.5.
    I have used this Telephone field in CF7 Generator, the fields ‘Regular expression to trigger changing to the alternative mask’ and ‘Regular expression to change back to the original mask’ are not very clear to me what to put here, but I think its for the custom regular expression validation pattern for the phone input.
    I have to make a phone (mobile no.) field for Indian User, 10 digit mobile number starting first digit with 9,8 or 7 only.

    I have used the regex /^[789]\d{9}$/i in my php code and its working fine 100%. (helped with link:

    Example code for php (which I used in wordpress for some other custom form):
    if(!preg_match(“/^[789]\d{9}$/i”, $mobileno))
    { $errMessage = ‘Mobile no. is invalid ‘.$mobileno;
    $err = true;

    But when I put the same regex in cf7 phone field generator, the code is like
    [phone* custphone mask:(999)999-9999 reDo:/^[789]\d{9}$/i reUndo:/^[789]\d{9}$/i]

    But the problem is, on saving the form, it displays the phone field wrong, breaking the regex from ‘\’ and displaying the regex string below the phone field. And validation not working.

    Is this plugin able to parse the regex with forward slash ‘\’?
    What I have to write in which field of generator to get my required validation working on this field?

    Please let me know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gabriel Reguly


    Hi Shashank Shekhar,

    The regular expression fields are for using different masks.

    One should use JavaScript regular expressions, not PHP regular expressions. (They have different sintaxes)

    Anyway, you should not need the regular expressions if you mask is always the same.

    For instance, this should do the trick

    [phone* custphone mask:(99)999-99999]

    Bear in mind that this plugin is a mask for better looking of the input, not a real input filter.


    Thanks for the info, but still not vary clear to me. I am not getting what, how and when to use redo undo regex fields? What to write in them when, and what they actually do in effect? Could you give me an example of it?

    Further, could u let me know if I can do my custom validation with this field 10 digit mobile no. starting with 9,8 or 7 only. If its possible to use javascript regex in place of php regex /^[789]\d{9}$/i , I am ready to use that. But I need help if u can provide me corresponding regex for example, and let me know if I can achieve the result what I want?

    Plugin Author Gabriel Reguly


    Hi Shashank,

    Here in Brazil, telephone numbers have 2 area code digits (99) and 8 digits for the actual number.

    So a mask like (99)9999-9999 is used.

    But we have an exception for São Paulo, area code 11,where some phone numbers have 9 digits instead of 8.

    Those numbers are like this (11)9xx-xxx-xxx

    So the plugin has the option for an alternate mask and those regular expressions, which are only for changing the masks.

    Here you can see a visual example


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘regular expression validation not working’ is closed to new replies.