From 7b75b07f1f03cb42ec3763318ffe2ead4bbd03d2 Mon Sep 17 00:00:00 2001 From: cketti Date: Sat, 13 Feb 2010 17:26:54 +0000 Subject: [PATCH] Fixes issue 849 --- src/com/fsck/k9/EmailAddressValidator.java | 12 ++++++++++-- .../fsck/k9/activity/setup/AccountSetupBasics.java | 5 +---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/EmailAddressValidator.java b/src/com/fsck/k9/EmailAddressValidator.java index f88fe6eb9..57c874951 100644 --- a/src/com/fsck/k9/EmailAddressValidator.java +++ b/src/com/fsck/k9/EmailAddressValidator.java @@ -1,11 +1,19 @@ package com.fsck.k9; -import android.text.util.Rfc822Tokenizer; +import java.util.regex.Pattern; + import android.widget.AutoCompleteTextView.Validator; public class EmailAddressValidator implements Validator { + // Source: http://www.regular-expressions.info/email.html + private static Pattern p = Pattern.compile( + "[a-z0-9!#$%&'*+/=?^_`{|}~-]+" + + "(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*" + + "@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+" + + "[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"); + public CharSequence fixText(CharSequence invalidText) { return ""; @@ -13,6 +21,6 @@ public class EmailAddressValidator implements Validator public boolean isValid(CharSequence text) { - return Rfc822Tokenizer.tokenize(text).length > 0; + return p.matcher(text).matches(); } } diff --git a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java index 69d9197b6..83853ca0d 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -134,10 +134,7 @@ public class AccountSetupBasics extends K9Activity boolean valid = Utility.requiredFieldValid(mEmailView) && Utility.requiredFieldValid(mPasswordView) && mEmailValidator.isValid(email); - - //FIXME: "foo@bar .com" will validate - - /*&& email.contains("@"); */ // Not sure if this is a good idea or not + mNextButton.setEnabled(valid); mManualSetupButton.setEnabled(valid); /*