-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?

2

3 Answers 3

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
2
  • 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. Jun 18, 2015 at 19:57
  • The question was tagged "Android" - that is the environment, hence my comment.
    – Jim
    Jun 19, 2015 at 9: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();
    }
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?

Not the answer you're looking for? Browse other questions tagged or ask your own question.