We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4610
    • 24 Posts
    I’m using the WebSignup snippet which you can elect to install with the default Modx install, along with the supplied FormSignup chunk. This should check that the email address entered into the form is in a valid format. Looking at the PHP code in websignup.inc.php there is this section

    // verify email
        if($email=='' || !ereg("^[-!#$%&'*+./0-9=?A-Z^_`a-z{|}~]+", $email)){
            $output = webLoginAlert("E-mail address doesn't seem to be valid!").$tpl;
            return;
        }


    This however doesn’t work as I can put anything into the email field and it’ll accept it. The server is running PHP version 5.2.10 and although the ereg function is listed as depreciated in PHP 5 it should still work. Is the reg exp supplied with the snippet actually wrong? What should it be to check that the email is in a valid format?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There are any number of regular expressions for checking email, just do a Google search.

      WebLoginPE uses
      eregi("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,7}$", $Email)


      To update any email validations code to use preg-match instead of the soon-to-be-deprecated ereg functions, there’s quite a discussion on the subject in the user comments here:
      http://us2.php.net/manual/en/function.preg-match.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4610
        • 24 Posts
        Ok, thanks for that. Strange that the regular expression supplied in the webuser login snippet doesn’t do what it’s supposed to though. That code was written 4 years ago.