0% found this document useful (0 votes)
45 views2 pages

Email Validation

The document discusses validating email addresses with a regular expression. It provides the asker's current regular expression and asks for suggestions to improve it. The answer suggests sending a validation link to the email address instead of solely relying on regular expressions, and doesn't propose changes to the provided regular expression.

Uploaded by

wpcarlos
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Email Validation

The document discusses validating email addresses with a regular expression. It provides the asker's current regular expression and asks for suggestions to improve it. The answer suggests sending a validation link to the email address instead of solely relying on regular expressions, and doesn't propose changes to the provided regular expression.

Uploaded by

wpcarlos
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

QUESTION:

I am just wondering what you would do to validate against an email address, basically I
want to know what Regular Expression you would use to check for a valid format. I've
seen so many different ways of doing it, some I can definitely say can produce wrong
results, but I'm not saying mine is perfect either, basically I want to perfect it.

Here's what I have, I use PHP's function eregi for this, so case is not important.
CODE
^[a-z][_.a-z0-9-]+@[a-z0-9][a-z0-9-]+\.[a-z]+([.]?[a-z][a-z]+)*

What I wanted to achieve was the first character of any email address should be a letter if
I'm not mistaken, I probably should go back and read the RFC 2822 as this should have
been my first stop in understanding how emails are handled and what is accepted and
what isn't. Next I allow an alphanumeric words with underscore, dot and hyphen (minus),
next comes the @ sign, after it I check again if the first character is a letter or number,
after that another alphanumeric word which allows hypens as well, I don't think you can
have an underscore in a domain name?, then comes a dot, then only a word with only
letters, I'm still wondering whether to include numbers or not, but so far seen no signs of
why I should. The last bit is the trickiest to make it work, basically it checks if another
dot follows, if so it checks that there's a letter afterwards then a word of only letters, so
there must exist at least 2 letters after the dot, if not, no match, it then continuously
checks it over an over again with the additional dots.

Which means something like [email protected] is valid, even if it does


not exist, but that's where checking the host comes into play.

It's that end part that worries me a bit though as it can accept a large amount of dots and
words over and over again, although I maybe able to find a limit in the RFC's so I will fix
that accordingly to it, else it may be a problem. Other than that, after verifying if the
email is valid, I would then check against DNS records or Hostname to see if the domain
of the email exists, I could query the sever if the user exists but most servers suggest the
user does even when they don't so I rather see if the host exists instead.

So what can you suggest to improve it? I know about shortform ways of writing it, but
this is how eregi accepts it. I will now go off and read the RFCs on it, might look at the
earlier one first before the newest.

ANSWER:
you can send them a link to validate their address...
you put the emailaddress in your db in a table that has two fields: the address and a
boolean value, default 0 and send them a link like:
yourhost.com/validate?mail=theiremail
and they you just put the boolean on 1

for the reg expression, can't really think of anything better than the one you have

You might also like