From e43a6a02dd9124079c69f3a5a01e16df4f85ee05 Mon Sep 17 00:00:00 2001 From: Satish Roddom Date: Fri, 21 Aug 2009 02:51:39 -0500 Subject: [PATCH] Compose Message "To" field allows adding sequence of characters as contact When we select this option, this sequence of characters (which is neither a valid email address nor a phone number), gets stored in contact with type MOBILE. Fix: In function canAddToContacts, adding a check to validate whether the contact to be added is a valid email address or phone number. If not, user will not be shown with the option "Add to Contacts". --- core/java/android/provider/Telephony.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java index 7a6f6bb5c0a22..0207330259e60 100644 --- a/core/java/android/provider/Telephony.java +++ b/core/java/android/provider/Telephony.java @@ -1263,6 +1263,21 @@ public final class Telephony { return match.matches(); } + /** + * Returns true if the number is a Phone number + * + * @param number the input number to be tested + * @return true if number is a Phone number + */ + public static boolean isPhoneNumber(String number) { + if (TextUtils.isEmpty(number)) { + return false; + } + + Matcher match = Regex.PHONE_PATTERN.matcher(number); + return match.matches(); + } + /** * Contains all MMS messages in the MMS app's inbox. */