summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPaul Westbrook <pwestbro@google.com>2010-09-30 14:56:43 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-09-30 14:56:43 -0700
commita8c3c446ef995680a8c98936cd286846fa1efc64 (patch)
treeb6680c36e606570e5f017e77c3702f8fb1cd1b14 /common
parent420b44b8b11ec1c309ea130e69a6876325dbfef9 (diff)
parentb4f5e0e5755938f2be9a2f1a1a6609b018c530ad (diff)
downloadandroid_frameworks_ex-a8c3c446ef995680a8c98936cd286846fa1efc64.tar.gz
android_frameworks_ex-a8c3c446ef995680a8c98936cd286846fa1efc64.tar.bz2
android_frameworks_ex-a8c3c446ef995680a8c98936cd286846fa1efc64.zip
am b4f5e0e5: Fixed the Rfc822Validator
Merge commit 'b4f5e0e5755938f2be9a2f1a1a6609b018c530ad' * commit 'b4f5e0e5755938f2be9a2f1a1a6609b018c530ad': Fixed the Rfc822Validator
Diffstat (limited to 'common')
-rw-r--r--common/java/com/android/common/Rfc822Validator.java2
-rw-r--r--common/tests/src/com/android/common/Rfc822ValidatorTest.java57
2 files changed, 58 insertions, 1 deletions
diff --git a/common/java/com/android/common/Rfc822Validator.java b/common/java/com/android/common/Rfc822Validator.java
index 087e425..1b4a268 100644
--- a/common/java/com/android/common/Rfc822Validator.java
+++ b/common/java/com/android/common/Rfc822Validator.java
@@ -45,7 +45,7 @@ public class Rfc822Validator implements AutoCompleteTextView.Validator {
* ".com", ".fr", etc...
*/
private static final Pattern EMAIL_ADDRESS_PATTERN =
- Pattern.compile("[^\\s@]+@[^\\s@]+\\.[a-zA-z][a-zA-Z][a-zA-Z]*");
+ Pattern.compile("[^\\s@]+@([^\\s@\\.]+\\.)+[a-zA-z][a-zA-Z][a-zA-Z]*");
private String mDomain;
diff --git a/common/tests/src/com/android/common/Rfc822ValidatorTest.java b/common/tests/src/com/android/common/Rfc822ValidatorTest.java
new file mode 100644
index 0000000..5118146
--- /dev/null
+++ b/common/tests/src/com/android/common/Rfc822ValidatorTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.common;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class Rfc822ValidatorTest extends TestCase {
+
+ @SmallTest
+ public void testEmailValidator() {
+ Rfc822Validator validator = new Rfc822Validator("gmail.com");
+ String[] validEmails = new String[] {
+ "a@b.com", "a@b.fr", "a+b@c.com", "a@b.info", "john@example.com", "john@example.fr",
+ "john@corp.example.com",
+ };
+
+ for (String email : validEmails) {
+ assertTrue(email + " should be a valid email address", validator.isValid(email));
+ }
+
+ String[] invalidEmails = new String[] {
+ "a", "a@b", "a b", "a@b.12", "john@example..com", "johnexample.com", "john.example.com"
+ };
+
+ for (String email : invalidEmails) {
+ assertFalse(email + " should not be a valid email address", validator.isValid(email));
+ }
+
+ Map<String, String> fixes = new HashMap<String, String>();
+ fixes.put("a", "<a@gmail.com>");
+ fixes.put("a b", "<ab@gmail.com>");
+ fixes.put("a@b", "<a@b>");
+
+ for (Map.Entry<String, String> e : fixes.entrySet()) {
+ assertEquals(e.getValue(), validator.fixText(e.getKey()).toString());
+ }
+ }
+}