Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Validation

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
I got the following code

Code:
LOCAL loRegExp

m_email = ThisForm.ContMaster.txtEmail.Value
loRegExp = CreateObject("VBScript.RegExp")
loRegExp.IgnoreCase = .T.
loRegExp.Pattern = '^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$'
m.valid = loRegExp.Test(m_email)
RELEASE loRegExp
IF m.valid = .T.
   MESSAGEBOX("Email is Correct",48)
ENDIF

through thread184-874813.

It is working fine, can I validate whether the email is active or not?

Thanks

Saif
 
No. The only way to know if it is an actual email address is to send a message to it and then see what reply you get, if any.

Think about it. There's no way that Foxpro, or anything else in your local system, can know whether someone has registered a particular email address somewhere in the world.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Here are a variety of RegEx expressions for validating email addresses.
However, as has been said above, they are only good to a certain extent - read their descriptions carefully.

Additionally I use the following site ( ) to confirm RegEx expressions against a group of test cases.
I put my RegEx expression into the 'Regular Expression' box and then go to down the left side and select: Unit Tests
I then put sample data into the: 'given the string' box and do an 'Add Test'
Finally just above the 'Test List' box on the right there is an Arrow.
Click on that Arrow and see if the test strings you entered Pass/Fail the check against the RegEx string you entered.

Good Luck,
JRB-Bldr
 
JRB, I might be wrong, but my understanding is that Saif already had the correct RegEx syntax for email addresses. What he is now looking for is a way to determine if a particular email address actually exists, that is, that it represents a valid user name at a valid mail server.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
JRB, I might be wrong, but my understanding is that Saif already had the correct RegEx syntax for email addresses. What he is now looking for is a way to determine if a particular email address actually exists, that is, that it represents a valid user name at a valid mail server.

Yes, exactly!

Saif
 
And the only thing, that can be repeated about that is, that you can't validate any mail address existence merely be a regular expression. That only assures the adress you pass in is valid against the pattern including letters, digits, an @ sign, again letters and digits and some more, eg dots, minus, a domain extension, so it merely checks the format of a mail address is right, there is no invalid char or missing component. sfhjksdhk@sdfjksdh.fun also passes the test, but surely this mail address is not used, even the domain sdfjksdh.fun doesn't exist.

There is no other way to validate an email address exists, than sending a mail to it with a verification link the user then has to click. Why else do all major communities ask that of you, if you register?

You'll not only technically verify the address is valid by sending a mail at it, which doesn't bounce off, you also let the owner of that mail address confirm the registration (or other actions), so a user can't register to impersonate someone just knowing a mail address, you'll have to have access to the mail address to activate the registered account, for example.

What you have to do is not only send any mail to the address, but a mail containing an individual confirmation link. If that links is clicked in the mail, you do not only know that mail address exists, but also the owner of the mail address wants to confirm it. Another common practice is not sending over a link, but a code and offering a page to enter that confirmation code. All these links or codes have to be unique and valid only one-time and for a limited time period, eg an hour or a day, depends on the need, because whatever script processes these link requests or entered confirmation codes will need to lookup the adress related to it, the account related to the address and accept the activation/confirmation.

For an example how it could be done: Don't waste your time understanding the php or mysql, just understand the concept. In this case the confirmation link contains a hash code made up in the mysql database for the users record, so the link does not expire and if the user doesn't want to confirm his account registration, someone else getting hands on the link can do so. The other thing I'd not do is send over username and password in the same mail. All info needed is there to take over this account and impersonate someone, but the general process of sending out a confirmation mail and processing a verification is explained quite well.

Bye, Olaf.
 
There is no other way to validate an email address exists, than sending a mail to it with a verification link the user then has to click. Why else do all major communities ask that of you, if you register?

And it's why so many spammers ask you to click a link. They can develop lists of "known valid" email addresses, which are highly valued in the spammer community. But the only way of building a list of "known valid" email addresses, short of stealing it from each and every domain, is to get the individual users to click a confirming link.
 
Or, for a different approach:

Focus on checking the syntax of the address rather the validity (which is what you are doing with your RegEx). Then, when you come to send out your email, be rigorous in dealing with bounce messages.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>be rigorous in dealing with bounce messages.

Well, more and more hosters default their mail servers to catch all. So all mails arrive, none bounce. You can't detect this way, whether a mail has a (human) owner.

Bye, Olaf.
 
Good point, Olaf. I suppose the answer depends on how and why Saif is collecting these addresses. Is it a mailing list of some kind, and he wants to remove any addresses which don't exist? Or are they addresses provided directly by users when registering at a website or subscribing to some service? If the latter, then he needs some sort of response system, as you suggested. If the former, it might be better not to worry about it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top