开发者

How to prepare Email Validation test case?

开发者 https://www.devze.com 2023-01-06 15:49 出处:网络
HI , I am writing a java program to validate email addresses. This program use Pattern class to validate the input string against the Regex pattern. I have procured Regex Pattern for th开发者_开发百科

HI ,

I am writing a java program to validate email addresses. This program use Pattern class to validate the input string against the Regex pattern. I have procured Regex Pattern for th开发者_开发百科e email validatation and my program is successfully working.

Now, I see some wrong email addresses in my database(Email delevery fails to these addresses.), So, i decided to prepare a test case that will run a validation on the handfull of email addresses list. I want this list to have all possible cases for a valid email address and invalid email address.

I am wondering if some has prepared email validatation test case before? If so Please Guide me to have this test case prepared with me?

Regards, VSD


This article contains some regexps which cover valid addresses.

There are no test cases, though. In your case, I suggest to try the usual approach: Take a couple (2-3) valid and invalid addresses and test that. If you find your code to accept an illegal address or reject a valid one, then extend the test.


Dominic Sayers has collected test cases from Cal Henderson, Dave Child, Phil Haack, Doug Lovell, RFC 5322 and RFC 3696, 222 test addresses in all (see this previous answer).

His stuff is available on his blog in RFC-compliant email address validator (in the results and analysis).

Just keep in mind that there is no perfect solution using regex, the grammar is too complex for that.

See also

  • What is the best regular expression for validating email addresses?


may this site http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html will provide you some help. But the only way to validate emails is to try to send one.


It sounds a lot like the emails are of the correct form but aren't actually registered. There's no way to check for that without actually emailing these addresses.

Is the problem that the emails aren't properly formed (eg asdf@foo) or that they're not registered accounts (emails getting bounced or ignored by the mailserver)?

0

精彩评论

暂无评论...
验证码 换一张
取 消