Drupal 6 user registration email validation problem

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
nicktr's picture

I've noticed that the user registration page in drupal 6 doesn't properly validate user email addresses. It allows users to register using an invalid address - without the period before the TLD e.g. user123@gmailcom

The user receives a message saying "Your password and further instructions have been sent to your e-mail address." But they obviously haven't......

Now, of course the user has to enter the incorrect email address twice on the registration form, which is unlikely, but it seems odd that such basic validation isn't performed.

I've searched around and can't seem to find much at all that discusses this, which surprises me at this seems like a pretty simple example where emil validation would be useful. It's not super important to have,

I realise there are PHP fucntions e.g. FILTER_VALIDATE_EMAIL that are designed to catch invalid email address, but could that be used within a custom Drupal module somehow? To validate the user registration form?

Thanks,

Nick,

Comments

Unfortunately

dalin's picture

Unfortunately validate_email() in D6 uses custom regexes. This is because the built-in filter_var() didn't come out until PHP 5.2 (The D6 minimum requirement for PHP are much lower). This system isn't plugable, so if you want D7's better filter you'll have to hack core. Luckily it's a very straightforward -6+1 patch.

Be sure to document your hack so that it gets re-applied for future updates to Drupal core.

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

Ok thanks, I found this

nicktr's picture

Ok thanks,
I found this patch

diff --git a/includes/common.inc b/includes/common.inc
index 075a840..288b3c6 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -964,7 +964,7 @@ function t($string, $args = array(), $langcode = NULL) {
  /
function valid_email_address($mail) {
   $user = '[a-zA-Z0-9_-.+\^!#\$%&
+\/\=\?`|{}~\']+';
-  $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-][a-zA-Z0-9]).?)+';
+  $domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]
[a-zA-Z0-9])(.[a-zA-Z0-9]+)+)+';
   $ipv4 = '[0-9]{1,3}(.[0-9]{1,3}){3}';
   $ipv6 = '[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){7}';

Which has done the trick nicely!

DrupalHK

Group categories

HKDUG Vocabulary

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: