android.util.Patterns Java Examples
The following examples show how to use
android.util.Patterns.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Customer.java From mobikul-standalone-pos with MIT License | 6 votes |
@Bindable public String getEmail() { if (email == null) { return ""; } else if (Patterns.EMAIL_ADDRESS.matcher(email).matches()) { Log.d(TAG, "getEmail: " + getCustomerId()); DataBaseController.getInstanse().checkEmailExist(getContext(), email, new DataBaseCallBack() { @Override public void onSuccess(Object responseData, String successMsg) { if (((Customer) responseData) != null && ((Customer) responseData).getCustomerId() != getCustomerId()) { isEmailExist = true; } else { isEmailExist = false; } Log.d(TAG, "onSuccess: " + responseData); } @Override public void onFailure(int errorCode, String errorMsg) { isEmailExist = false; } }); } return email; }
Example #2
Source File: VerifyOTP.java From XERUNG with Apache License 2.0 | 6 votes |
private ArrayList<String> getUserEmail(){ ArrayList<String> email = new ArrayList<String>(); Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; if(possibleEmail != null) if(possibleEmail.length() !=0 ){ email.add(possibleEmail); } } } return email; }
Example #3
Source File: VerifyOTP.java From XERUNG with Apache License 2.0 | 6 votes |
private ArrayList<String> getUserEmail(){ ArrayList<String> email = new ArrayList<String>(); Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ Account[] accounts = AccountManager.get(VerifyOTP.this).getAccounts(); for (Account account : accounts) { if (emailPattern.matcher(account.name).matches()) { String possibleEmail = account.name; if(possibleEmail != null) if(possibleEmail.length() !=0 ){ email.add(possibleEmail); } } } return email; }
Example #4
Source File: LoginCredentials.java From Android-Tutorials with Apache License 2.0 | 6 votes |
public boolean isValid() { if (TextUtils.isEmpty(username)) { return false; } if (!Patterns.EMAIL_ADDRESS.matcher(username).matches()) { return false; } if (TextUtils.isEmpty(password)) { return false; } if (password.length() < 5) { return false; } return true; }
Example #5
Source File: EmailSignupProvider.java From argus-android with Apache License 2.0 | 6 votes |
@Override protected View inflateView(ViewGroup parentView) { if (context != null) { getValidationEngine() .addEmailValidation(new RegexValidation(Patterns.EMAIL_ADDRESS.pattern(), context.getString( R.string.invalid_email))); } View signUpView = LayoutInflater.from(context) .inflate(R.layout.signup_email, parentView, false); usernameEt = (EditText) signUpView.findViewById(R.id.username); emailEt = (EditText) signUpView.findViewById(R.id.email); passwordEt = (EditText) signUpView.findViewById(R.id.password); welcomeTv = (TextView) signUpView.findViewById(R.id.tv_welcome_text); theme = Argus.getInstance().getArgusTheme(); themeHelper.applyTheme(signUpView, theme); return signUpView; }
Example #6
Source File: LoginInteractor.java From Android-Tutorials with Apache License 2.0 | 6 votes |
private boolean hasError(LoginCredentials loginCredentials) { String username = loginCredentials.getUsername(); String password = loginCredentials.getPassword(); if (TextUtils.isEmpty(username)) { loginListener.onFailed("The email is empty"); return true; } if (!Patterns.EMAIL_ADDRESS.matcher(username).matches()) { loginListener.onFailed("The email is invalid"); return true; } if (TextUtils.isEmpty(password)) { loginListener.onFailed("The password is empty"); return true; } if (password.length() < 5) { loginListener.onFailed("Password is weak"); return true; } return false; }
Example #7
Source File: UiUtils.java From tindroid with Apache License 2.0 | 6 votes |
static Credential parseCredential(String cred) { final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); final String country = Locale.getDefault().getCountry(); if (Patterns.PHONE.matcher(cred).matches()) { // Looks like a phone number. try { // Normalize phone number format cred = phoneUtil.format(phoneUtil.parse(cred, country), PhoneNumberUtil.PhoneNumberFormat.E164); // Exception not thrown, we have a phone number. return new Credential(Credential.METH_PHONE, cred); } catch (NumberParseException ignored) { return null; } } // Not a phone number. Try parsing as email. if (Patterns.EMAIL_ADDRESS.matcher(cred).matches()) { return new Credential(Credential.METH_EMAIL, cred); } return null; }
Example #8
Source File: AndroidShareDialog.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public AndroidShareDialog(Context context, int theme, String msgText, final String imgUri) { super(context, theme); this.msgText = msgText; if(TextUtils.isEmpty(imgUri)){ this.mImgPath = null;// getAppLauncherPath(); }else{ if (Patterns.WEB_URL.matcher(imgUri).matches()) { new Thread(new Runnable() { public void run() { try { mImgPath = getImagePath(imgUri, getFileCache()); } catch (Exception e) { e.printStackTrace(); } } }).start(); } else { this.mImgPath = imgUri; } } }
Example #9
Source File: DesignerNewsLogin.java From android-proguards with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") private void setupAccountAutocomplete() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { permissionPrimer.setVisibility(View.GONE); final Account[] accounts = AccountManager.get(this).getAccounts(); final Set<String> emailSet = new HashSet<>(); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { emailSet.add(account.name); } } username.setAdapter(new ArrayAdapter<>(this, R.layout.account_dropdown_item, new ArrayList<>(emailSet))); } else { if (shouldShowRequestPermissionRationale(Manifest.permission.GET_ACCOUNTS)) { setupPermissionPrimer(); } else { permissionPrimer.setVisibility(View.GONE); shouldPromptForPermission = true; } } }
Example #10
Source File: WebUtils.java From SendBird-Android with MIT License | 6 votes |
/** * Extract urls from string. * @param input * @return */ public static List<String> extractUrls(String input) { List<String> result = new ArrayList<String>(); String[] words = input.split("\\s+"); Pattern pattern = Patterns.WEB_URL; for(String word : words) { if(pattern.matcher(word).find()) { if(!word.toLowerCase().contains("http://") && !word.toLowerCase().contains("https://")) { word = "http://" + word; } result.add(word); } } return result; }
Example #11
Source File: EmailAccountCreationAssistantActivity.java From linphone-android with GNU General Public License v3.0 | 6 votes |
@Override protected void onResume() { super.onResume(); Core core = LinphoneManager.getCore(); if (core != null) { reloadLinphoneAccountCreatorConfig(); } getAccountCreator().addListener(mListener); if (getResources().getBoolean(R.bool.pre_fill_email_in_assistant)) { Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); for (Account account : accounts) { if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) { String possibleEmail = account.name; mEmail.setText(possibleEmail); break; } } } }
Example #12
Source File: ConverterTextToHtml.java From Android-RTEditor with Apache License 2.0 | 6 votes |
private static void linkifyText(final String text, final StringBuffer outputBuffer) { String prepared = replaceAll(text, BITCOIN_URI_PATTERN, "<a href=\"$0\">$0</a>"); Matcher m = Patterns.WEB_URL.matcher(prepared); while (m.find()) { int start = m.start(); if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) { if (m.group().indexOf(':') > 0) { // With no URI-schema we may get "http:/" links with the second / missing m.appendReplacement(outputBuffer, "<a href=\"$0\">$0</a>"); } else { m.appendReplacement(outputBuffer, "<a href=\"http://$0\">$0</a>"); } } else { m.appendReplacement(outputBuffer, "$0"); } } m.appendTail(outputBuffer); }
Example #13
Source File: ContentBlocker57.java From SABS with MIT License | 6 votes |
@Override public boolean enableBlocker() { //contentBlocker56.setUrlBlockLimit(15_000); if (contentBlocker56.enableBlocker()) { SharedPreferences sharedPreferences = App.get().getApplicationContext().getSharedPreferences("dnsAddresses", Context.MODE_PRIVATE); if (sharedPreferences.contains("dns1") && sharedPreferences.contains("dns2")) { String dns1 = sharedPreferences.getString("dns1", null); String dns2 = sharedPreferences.getString("dns2", null); if (dns1 != null && dns2 != null && Patterns.IP_ADDRESS.matcher(dns1).matches() && Patterns.IP_ADDRESS.matcher(dns2).matches()) { this.setDns(dns1, dns2); } Log.d(TAG, "Previous dns addresses has been applied. " + dns1 + " " + dns2); } return true; } return false; }
Example #14
Source File: AccountUtils.java From evercam-android with GNU Affero General Public License v3.0 | 6 votes |
/** * Retrieves the user profile information in a manner supported by * Gingerbread devices. * * @param context the context from which to retrieve the user's email address * and name * @return a list of the possible user's email address and name */ private static UserProfile getUserProfileOnGingerbreadDevice(Context context) { // Other that using Patterns (API level 8) this works on devices down to // API level 5 final Matcher valid_email_address = Patterns.EMAIL_ADDRESS.matcher(""); final Account[] accounts = AccountManager.get(context).getAccountsByType(GoogleAuthUtil .GOOGLE_ACCOUNT_TYPE); UserProfile user_profile = new UserProfile(); // As far as I can tell, there is no way to get the real name or phone // number from the Google account for (Account account : accounts) { if (valid_email_address.reset(account.name).matches()) user_profile.addPossibleEmail(account.name); } // Gets the phone number of the device is the device has one if (context.getPackageManager().hasSystemFeature(Context.TELEPHONY_SERVICE)) { final TelephonyManager telephony = (TelephonyManager) context.getSystemService (Context.TELEPHONY_SERVICE); user_profile.addPossiblePhoneNumber(telephony.getLine1Number()); } return user_profile; }
Example #15
Source File: ConverterTextToHtml.java From memoir with Apache License 2.0 | 6 votes |
private static void linkifyText(final String text, final StringBuffer outputBuffer) { String prepared = replaceAll(text, BITCOIN_URI_PATTERN, "<a href=\"$0\">$0</a>"); Matcher m = Patterns.WEB_URL.matcher(prepared); while (m.find()) { int start = m.start(); if (start == 0 || (start != 0 && text.charAt(start - 1) != '@')) { if (m.group().indexOf(':') > 0) { // With no URI-schema we may get "http:/" links with the second / missing m.appendReplacement(outputBuffer, "<a href=\"$0\">$0</a>"); } else { m.appendReplacement(outputBuffer, "<a href=\"http://$0\">$0</a>"); } } else { m.appendReplacement(outputBuffer, "$0"); } } m.appendTail(outputBuffer); }
Example #16
Source File: TextViewClickMovement.java From NMSAlphabetAndroidApp with MIT License | 6 votes |
@Override public boolean onSingleTapConfirmed(MotionEvent event) { final String linkText = getLinkText(tex, spannable, event); LinkType linkType = LinkType.NONE; if (Patterns.PHONE.matcher(linkText).matches()) { linkType = LinkType.PHONE; } else if (Patterns.WEB_URL.matcher(linkText).matches()) { linkType = LinkType.WEB_URL; } else if (Patterns.EMAIL_ADDRESS.matcher(linkText).matches()) { linkType = LinkType.EMAIL_ADDRESS; } if (listener != null) { listener.onLinkClicked(linkText, linkType); } return false; }
Example #17
Source File: MainActivity.java From aard2-android with GNU General Public License v3.0 | 6 votes |
@Override public void onWindowFocusChanged(boolean hasFocus) { ClipboardManager cm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE); ClipData clipData = cm.getPrimaryClip(); if (clipData == null) { return; } int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); CharSequence text = item.getText(); if (text != null && text.length() > 0) { if (Patterns.WEB_URL.matcher(text).find()) { Log.d(TAG, "Text contains web url, not pasting: " + text); return; } viewPager.setCurrentItem(0); cm.setPrimaryClip(ClipData.newPlainText(null, "")); appSectionsPagerAdapter.tabLookup.setQuery(text.toString()); break; } } }
Example #18
Source File: LinkUtils.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Returns a list with all links contained in the input */ public static List<String> extractUrls(String text) { List<String> containedUrls = new ArrayList<>(); Pattern pattern = Patterns.WEB_URL; Matcher urlMatcher = pattern.matcher(text); while (urlMatcher.find()) { containedUrls.add(text.substring(urlMatcher.start(0), urlMatcher.end(0))); } return containedUrls; }
Example #19
Source File: ActionSendActivity.java From LocationPrivacy with GNU General Public License v3.0 | 5 votes |
private String replaceUrls(String text) { if (TextUtils.isEmpty(text)) return text; Matcher m = Patterns.WEB_URL.matcher(text); while (m.find()) { String foundUrl = m.group(0); String replaceUrl = getPrivateUrl(foundUrl, m.group(2), m.group(3)); if (!TextUtils.equals(foundUrl, replaceUrl)) text = text.replace(foundUrl, replaceUrl); } return text; }
Example #20
Source File: RequestParser.java From Lanmitm with GNU General Public License v2.0 | 5 votes |
public static String getBaseDomain(String hostname) { String domain = ""; // if hostname is an IP address return that address if (Patterns.IP_ADDRESS.matcher(hostname).matches()) return hostname; for (String tld : TLD) { if (hostname.endsWith(tld)) { String[] host_parts = hostname.split("\\."), tld_parts = tld .split("\\."); int itld = tld_parts.length, ihost = host_parts.length, i = 0, stop = ihost - 1; domain = ""; for (i = ihost - itld; i <= stop; i++) { domain += host_parts[i] + (i == stop ? "" : "."); } return domain; } } int startIndex = 0, nextIndex = hostname.indexOf('.'), lastIndex = hostname .lastIndexOf('.'); while (nextIndex < lastIndex) { startIndex = nextIndex + 1; nextIndex = hostname.indexOf('.', startIndex); } if (startIndex > 0) return hostname.substring(startIndex); else return hostname; }
Example #21
Source File: AccountUtils.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
public static List<String> getDeviceAccountsEmailAddresses(final Context context) { final ArrayList<String> retval = new ArrayList<>(); for (final Account account : getAccounts(context)) { final String name = account.name; if (Patterns.EMAIL_ADDRESS.matcher(name).matches()) { retval.add(name); retval.add(name.split("@")[0]); } } return retval; }
Example #22
Source File: AutoInstallsLayout.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
protected Intent parseIntent(XmlResourceParser parser) { final String url = getAttributeValue(parser, ATTR_URL); if (TextUtils.isEmpty(url) || !Patterns.WEB_URL.matcher(url).matches()) { if (LOGD) Log.d(TAG, "Ignoring shortcut, invalid url: " + url); return null; } return new Intent(Intent.ACTION_VIEW, null).setData(Uri.parse(url)); }
Example #23
Source File: MiscUtils.java From caffeine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Uses androids android.util.Patterns.EMAIL_ADDRESS to check if an email address is valid. * * @param email Address to check * @return true if the <code>email</code> is a valid email address. */ public final static boolean isValidEmail(String email) { if (email == null) { return false; } else { return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches(); } }
Example #24
Source File: SocialTextView.java From social-text-view with MIT License | 5 votes |
/** * Checks which flags are enable so that the appropriate link items can be * collected from each respective mode. * * @param text Text * @return Set of {@link LinkItem} */ private Set<LinkItem> collectLinkItemsFromText(String text) { final Set<LinkItem> items = new HashSet<>(); // Check for hashtag links, if possible if ((flags & HASHTAG) == HASHTAG) { collectLinkItems(HASHTAG, items, getHashtagPattern().matcher(text)); } // Check for mention links, if possible if ((flags & MENTION) == MENTION) { collectLinkItems(MENTION, items, getMentionPattern().matcher(text)); } // Check for phone links, if possible if ((flags & PHONE) == PHONE) { collectLinkItems(PHONE, items, Patterns.PHONE.matcher(text)); } // Check for url links, if possible if ((flags & URL) == URL) { collectLinkItems(URL, items, Patterns.WEB_URL.matcher(text)); } // Check for email links, if possible if ((flags & EMAIL) == EMAIL) { collectLinkItems(EMAIL, items, Patterns.EMAIL_ADDRESS.matcher(text)); } return items; }
Example #25
Source File: AdWebView.java From mobile-sdk-android with Apache License 2.0 | 5 votes |
private boolean isValidUrl(String url) { try { new URL(url).toURI(); return Patterns.WEB_URL.matcher(url).matches(); } catch (MalformedURLException | URISyntaxException e) { e.printStackTrace(); return false; } }
Example #26
Source File: RegistrationActivity.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
private void verifyServer(TextInputEditText view) { String error = getString(R.string.login_error_server); String server = view.getText().toString(); if (!TextUtils.isEmpty(server) && !Patterns.DOMAIN_NAME.matcher(server).matches() && !Patterns.IP_ADDRESS.matcher(server).matches() && !Patterns.WEB_URL.matcher(server).matches()) { view.setError(error); } }
Example #27
Source File: UrlHelper.java From wallpaperboard with Apache License 2.0 | 5 votes |
public static Type getType(String url) { if (url == null) return Type.INVALID; if (!URLUtil.isValidUrl(url)) { if (Patterns.EMAIL_ADDRESS.matcher(url).matches()) { return Type.EMAIL; } return Type.INVALID; } if (url.contains("behance.")) { return Type.BEHANCE; } else if (url.contains("dribbble.")) { return Type.DRIBBBLE; } else if (url.contains("facebook.")) { return Type.FACEBOOK; } else if (url.contains("github.")) { return Type.GITHUB; } else if (url.contains("plus.google.")) { return Type.GOOGLE_PLUS; } else if (url.contains("instagram.")) { return Type.INSTAGRAM; } else if (url.contains("pinterest.")) { return Type.PINTEREST; } else if (url.contains("twitter.")) { return Type.TWITTER; } else { return Type.UNKNOWN; } }
Example #28
Source File: RVEValidatorFactory.java From RippleValidatorEditText with Apache License 2.0 | 5 votes |
private static RVEValidator PhoneNumberChecker(String error){ return new RVEValidator(error) { @Override public boolean isValid(@NonNull CharSequence text) { Boolean isNumber= Patterns.PHONE.matcher(text).matches(); if(!isNumber) { return false; } return true; } }; }
Example #29
Source File: ValidatorUtils.java From Cangol-appcore with Apache License 2.0 | 5 votes |
/** * 验证IP地址格式正确 255.255.255.255 * * @param str * @return */ public static boolean validateIP(String str) { if (str == null || "".equals(str)) { return false; } final Pattern p = Patterns.IP_ADDRESS; final Matcher m = p.matcher(str); return m.matches(); }
Example #30
Source File: ValidatorUtils.java From Cangol-appcore with Apache License 2.0 | 5 votes |
/** * 验证电话号码格式是否正确 * * @param str * @return */ public static boolean validatePhone(String str) { if (str == null || "".equals(str)) { return false; } final Pattern p = Patterns.PHONE; final Matcher m = p.matcher(str); return m.matches(); }