Link phone numbers with Regex

I am trying to chain phonenumbers using regular expressions, but I cannot apply it on my setText ();

I have a lot of googled, and it seems to me that they are really close to success.

Code I received:

if(tag.equals("Customer")) { String name = xpp.getAttributeValue(null, separated_nodes[0].trim()); String number = xpp.getAttributeValue(null, separated_nodes[1].trim()); String SSNumber = xpp.getAttributeValue(null, separated_nodes[2].trim()); String Address = xpp.getAttributeValue(null, separated_nodes[3].trim()); String Postcode = xpp.getAttributeValue(null, separated_nodes[4].trim()); String City = xpp.getAttributeValue(null, separated_nodes[5].trim()); String Phone = "Phone#: " + xpp.getAttributeValue(null, separated_nodes[6].trim()); String Cell = xpp.getAttributeValue(null, separated_nodes[7].trim()); String Email = xpp.getAttributeValue(null, separated_nodes[8].trim()); // text.setText("Network "+xpp.getAttributeValue(null, "Name")); Pattern pattern = Pattern.compile("[0]{1}[0-9]{6,15}"); Linkify.addLinks(text, pattern, "Phone#: "); //Linkify.addLinks(text, pattern, xmlstring); //Linkify.addLinks(text, pattern, Phone); text.setText("Customer: \nName: " + name +"\n" + "Customer Number: "+ number + "\n" + "Social Security Number: "+ SSNumber +"\n" + "Address: "+ Address +"\n" + "Postal Code: "+ Postcode +"\n" + "City: "+ City +"\n" + ""+ Phone +"\n" + "Cellphone#: "+ Cell +"\n" + "e-mail: "+ Email +"\n"); Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES) ; } 

As you can see, ive tried several ways to associate a phone number and a mobile phone.

I think RegEx is correct.

+1
source share
2 answers
  • you need to call Linkify.addLinks() AFTER you have configured the text view, you do this before
  • Does not bind already supported phone numbers, for example. Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS) ?

Update

Also here: Linkify.addLinks(text, pattern, "Phone#: "); the third argument should be Scheme , "Phone #:" is NOT a valid scheme. It should be tel: .

+1
source

Sorry call

 Linkify.addLinks(text, Linkify.EMAIL_ADDRESSES) 

on the last line, destroys the Spannables that were caused by previous calls to Linkify.addLinks (). See Link Documentation

0
source

Source: https://habr.com/ru/post/886458/


All Articles