We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19252
    • 9 Posts
    Hello,

    I am trying to add a regular expression validator so a text field only allows alpha-numeric characters, the - and _

    Here is the code I have in the chunk:
    <input maxlength="60" name="name" type="text" eform="Your Name:string:1:required field or invalid characters:#REGEX [a-zA-Z0-9_.-] " />

    When I test this with valid entries such as "Name" it still gives an error.

    Am I not formatting something correctly in the regular expression or parameters? undecided

    Thanks for any help.

    Judith
      • 7455
      • 2,204 Posts
      try this: [a-zA-Z0-9_.-].+

      Dimmy
        follow me on twitter: @dimmy01
        • 19252
        • 9 Posts
        I got it working laugh !! The eForm uses preg_match() php function and it’s rules not ereg(). As a result the regular expression needs to be enclosed in forward slashes. Here is the code that is now working:

        <input name="name" id="name" class="text" type="text" eform="name::1:Only letters and numbers allowed:#REGEX /^[A-za-z0-9’ _.-]+$/"/>

        Hope this will assist everyone.