0
你好,我正在努力從最後的isValid方法返回什麼我基本上需要檢查一個電子郵件地址是否有效,請任何和所有幫助表示讚賞。使用正則表達式驗證標識符
public class EmailAddress {
private static final String x = "[a - z]";
private static final String y = "[a-z0-9]";
private static final String id = x + y;
private String address;
public EmailAddress(String address) {
this.address = address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
/**
* Verify that a string is an email address.
* The string must obey the following (somewhat strict format)
* <email> ::= <identifier> @ <identifier> {. <identifier>}
* <identifier> ::= letter { letter | digit }
**/
public boolean isValid() {
if (address == null) return false;
String check = (id + "@" + id + "{." + id + "}");
return
}
}
這是我的JUtil測試代碼:
public class TestEmail {
private EmailAddress address;
@Test
public void replaceMe() {
assertTrue(true);
}
@Test
public void shouldAcceptJohnAtCsDotEdu() {
EmailAddress ea = new EmailAddress("[email protected]");
assertTrue(ea.isValid());
}
@Test
public void shouldNotAccept123AtCsDotEdu() {
EmailAddress ea = new EmailAddress("[email protected]");
assertFalse(ea.isValid());
}
}
編輯:這是測試代碼,我已經爲這個項目
true或false ... – 2014-09-27 03:43:46
我知道這是愚蠢的我只是絕對卡住也許是因爲它遲到了。我想我應該檢查別的東西?我也可以發佈我的測試文件。 – 2014-09-27 03:44:50