DelphiFAQ Home Search:

Handy function if an email field was filled out properly


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.


I need to check whether a user filled out the email field with a valid email address. Any ideas?


The only way to prove it is valid is to send a confirmation email with some secret url and or code to that email address, have the user read the email and click on the URL that comes in it. That way you verify that the user provided an email that actually exists.

Sometimes you can rely on the user's strong interest to provide a valid email address or you simply do not want to wait until the user has completed this process.

And even if you send the confirmation email, it does not hurt to do a syntactical check. The following code checks if there is an @ and a dot in the email address.

Note that theoretically an email does not necessarily contain the @ sign - e.g. it could be coded as %64 (which corresponds to the @ symbol).

function isEmail(str) 	{
if ((str == null) || 
            (str.length == 0) || 
            (str.indexOf("@")) == -1 || 
            (str.indexOf(".")) == -1) 
  return false; 
else { 
  return true; 


2012-11-12, 02:12:52
coach001 from United Kingdom  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: