-1

There is anyway to check if in text which I get from webservice is address email? I get long text and need to check where is email address and make it clickable. Any idea how can I do that?

HBG
  • 1,731
  • 2
  • 23
  • 35
edi233
  • 3,511
  • 13
  • 56
  • 97
  • 2
    This post might help you: http://stackoverflow.com/questions/6119722/how-to-check-edittexts-text-is-email-address-or-not?rq=1 – Kristy Welsh Jun 17 '15 at 17:07
  • Does this answer your question? [How to check edittext's text is email address or not?](https://stackoverflow.com/questions/6119722/how-to-check-edittexts-text-is-email-address-or-not) – leonheess Feb 09 '20 at 16:26

3 Answers3

2

Use a regular expression to parse the text for the email pattern http://www.regular-expressions.info/email.html

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b
Phil Cazella
  • 854
  • 5
  • 11
  • once the text is parsed from the string, the OP can use the resulting address any way they see fit. Obviously to make something "clickable" it needs to be presented to the user in either HTML or another type of UI. Without knowing the environment, I can't suggest a strategy for the display of that text. – Phil Cazella Jun 18 '15 at 19:57
  • The question was tagged "Android" - that is the environment, hence my comment. – Jim Jun 19 '15 at 09:25
1

this might help

public static boolean isValidEmailAddress(String email) {
        String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
        java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
        java.util.regex.Matcher m = p.matcher(email);
        return m.matches();
    }
Shaz
  • 302
  • 3
  • 13
1

To check whether it is a valid email address, there are lots of answers (including some here). But to make it clickable, use Linkify:

http://developer.android.com/reference/android/text/util/Linkify.html

An example/explanation:

Does Linkify work for TextView in Android?

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36