Recently I was posed with a question using one of my favourite CMS’s, namely CMSMS. As will all apps that require email addresses, making sure it’s a valid email address is not as easy you would think. Coupled with the possibility of underscores, dashes, plus signs, etc, it can be a nightmare.
The FrontEndUser Module is a great addition, where it allows you to have a login for your site, and display certain parts of templates whether a user is logged in or not. Sadly their email validation is slightly flawed, as it didn’t like email addresses with dashes in the username part.
I came across a great post titled “Comparing E-mail Address Validating Regular Expressions” , which show various examples of what regular expressions will match and check for valid email addresses.
FrontEndUser Fix
To fix the FrontEndUser module to allow dashes (some of you call them hyphens) you can take the following steps
- go to /modules/FrontEndUsers/FrontEndUsers.api.php
- find the function IsValidEmailAddress around line 965
- comment out :
if( !eregi("^[_a-z0-9-\.-]+(\.[_a-z0-9-\.-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email ) )
- and replace it with
$reg ='/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i';
if( preg_match($reg, $email ) )