That fuck shit the fascists are using
1/**
2 * Copyright (C) 2012 Whisper Systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package org.tm.archive.phonenumbers;
18
19import android.telephony.PhoneNumberUtils;
20
21import java.util.regex.Matcher;
22import java.util.regex.Pattern;
23
24public class NumberUtil {
25
26 private static final Pattern EMAIL_PATTERN = android.util.Patterns.EMAIL_ADDRESS;
27 private static final Pattern PHONE_PATTERN = android.util.Patterns.PHONE;
28
29 public static boolean isValidEmail(String number) {
30 Matcher matcher = EMAIL_PATTERN.matcher(number);
31 return matcher.matches();
32 }
33
34 public static boolean isVisuallyValidNumber(String number) {
35 Matcher matcher = PHONE_PATTERN.matcher(number);
36 return matcher.matches();
37 }
38
39 /**
40 * Whether or not a number entered by the user is a valid phone or email address. Differs from
41 * {@link #isValidSmsOrEmail(String)} in that it only returns true for numbers that a user would
42 * enter themselves, as opposed to the crazy network prefixes that could theoretically be in an
43 * SMS address.
44 */
45 public static boolean isVisuallyValidNumberOrEmail(String number) {
46 return isVisuallyValidNumber(number) || isValidEmail(number);
47 }
48
49 public static boolean isValidSmsOrEmail(String number) {
50 return PhoneNumberUtils.isWellFormedSmsAddress(number) || isValidEmail(number);
51 }
52}