We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31341
    • 15 Posts
    I added custom REGEX functions to validate "Zipcode" and US "Telephone Number " and received the following error:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
    Error type/ Nr.: Warning - 2
    File: /home/.jubilation/dhvcadmin/ajnag.com/assets/snippets/eform/eform.inc.php
    Line: 956
    Line 956 source: if( !$tmp=preg_match($param,$value) )

    Parser timing
    MySQL: -1.5011 s (6 Requests)
    PHP: 3.2405 s
    Total: 1.7394 s


    The Form Code:
    <p><span style="color:#900;">[+validationmessage+]</span></p>
    <form method="post" action="[~[*id*]~]">
        <input type="hidden" name="formid" value="feedbackForm" />
        
        <p><label accesskey="n" for="Name">Business Name</label>
        <input class="field" type="text" name="name" maxlength="40" eform="Business Name:string:1" />
    	
    	
    	</p>
    	
    	<p><label for="Address">Street Address</label><input name="address" type="text" eform="Address::1:" /></p>
    	
    	<p><label for="Address">City</label><input name="city" type="text" eform="City::1:" /></p>
    	
    	<p><label for="Address">Zipcode</label><input name="zip" type="text" eform="Zip::1::#REGEX \d{5}(-\d{4})?" /></p>
    	
    	<p><label for="Phone">Telephone</label><input name="number" type="text" eform="Phone Number:1::#REGEX '^[(]?[2-9]{1}[0-9]{2}[) -]{0,2}' . '[0-9]{3}[- ]?' . '[0-9]{4}[ ]?' . '((x|ext)[.]?[ ]?[0-9]{1,5})?$';" /></p>
    
        <p><label accesskey="e" for="email">Your Email Address</label>
        <input type="text" name="email" size="40" maxlength="40" eform="Your Email Address:email:1" /></p>
        
       <p><label for="Hours">Hours of Operation</label><input name="hours" type="text" eform="Hours::1:" /></p>
        
        <p><label accesskey="c" for="comments">Comments</label>
        <textarea cols="40" rows="10" name="comments" eform="Comments:html:1"></textarea></p>
    
        <p>
        Please enter the     anti spam code below:<br />
        <img src="[+verimageurl+]" alt="verification code" border="1"/>
        </p>
        <p>
        <label accesskey="c" for="vericode">Code</label>
        <input type="text" name="vericode" size="20" />
        </p>
        
        <p><input type="submit" name="submit" value="Send Feedback"></p>
    </form> 



    Any Ideas as to what is going on?

    Thanks
    -Devin
      • 30223
      • 1,010 Posts
      You need to enclose your regular expression within valid delimiters. The syntax for the regular expression is based on php’s preg_match() syntax.

      <input name="zip" type="text" eform="Zip::1::#REGEX #\d{5}(-\d{4})?#" />
      	
      <input name="number" type="text" eform="Phone Number:1::#REGEX '#^[(]?[2-9]{1}[0-9]{2}[) -]{0,2}' . '[0-9]{3}[- ]?' . '[0-9]{4}[ ]?' . '((x|ext)[.]?[ ]?[0-9]{1,5})?$';#" />


      should do the trick.
        • 31341
        • 15 Posts
        Thanks Toby, did the trick!