RSS

Newsletter

The CodeKarate Newsletter is the best way for technical ninjas to keep their swords sharpened. Don't worry, we won't flood your inbox and your email address will always remain private.
Back to Top

Validating an Email Address in Drupal

Ran into a situation earlier today where I needed to validate a Drupal username and email address entered into a custom form that would create a Drupal 6 User account (see http://codekarate.com/content/create-user-account-drupal-6-programmatically for more information on the submit handler of the form). There are easy to use Drupal functions to validate the username and email addresses. See the examples below:

//check if this is a valid Drupal username
user_validate_name('USERNAME');
 
//check if this is a valid email address
user_validate_mail('test@test.com');

These two functions helped a lot in my validation handler and hopefully they can help you.

Discussions

1
webmaster (not verified)

test email domian

Are there any Drupal modules that allow you to test the domain of a potential registrant's email, and reject if it doesn't match a required domain?

I have a school district, and I only want to accept registrations for teachers in that school district. I want to be able to test the domain of the email (schooldistrict.org) for example, and if the email doesn't have that domain, I want to disregard the registration (though I would prefer to give the user the impression that their registration request is being considered even though it is disregarded).

Any suggestions?

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <php>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <python>, <ruby>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.