ForumCategory: Android“real_time_masking_regex” not working
david.alderson asked 49 years ago

This is the regex I have for masking only the digits of a phone number and numbers of length 9+. I’ve tested this on regex test and debug sites, and it works there, but doesn’t mask in LP.

\d{9,}|\d{3}(?=[)-]?\d{3}[-]?\d{4})|(?<=\d{3}[)-]?)\d{3}(?=[-]?\d{4})|(?<=\d{3}[)-]?\d{3}[-]?)\d{4}

I also tried wrapping this in ![CDATA[]] without success.

Thanks!

Should highlight just digits in numbers like:
(123)456-7890
123-456-7890
123456789
1234567889999999999999
3 Answers
Best Answer
david.alderson answered 9 months ago

I fixed it. I wasn’t escaping correctly. Here’s the string def for masking phone digits and numbers with 9+ digits:

<string name="client_only_masking_regex">\\d{9,}|\\d{3}(\?=[)-]\?\\d{3}[-]\?\\d{4})|(\?&lt;=\\d{3}[)-]\?)\\d{3}(\?=[-]\?\\d{4})|(\?&lt;=\\d{3}[)-]\?\\d{3}[-]\?)\\d{4}</string>
David Villacis answered 9 months ago

Hi @david.alderson,
I tested your regex and I only got matches for 123456789 &1234567889999999999999:
 

Attachments
david.alderson answered 9 months ago

Regular regex:
\d{9,}|\d{3}(?=[)-]?\d{3}[-]?\d{4})|(?<=\d{3}[)-]?)\d{3}(?=[-]?\d{4})|(?<=\d{3}[)-]?\d{3}[-]?)\d{4}
 
Android strings.xml regex:
\\d{9,}|\\d{3}(\?=[)-]\?\\d{3}[-]\?\\d{4})|(\?&lt;=\\d{3}[)-]\?)\\d{3}(\?=[-]\?\\d{4})|(\?&lt;=\\d{3}[)-]\?\\d{3}[-]\?)\\d{4}

Attachments