How to mask input with regular expressions? either 1112223333 or 1112223333444

This is in the xaml file.

I need to mask an input field with a regular expression.

I need it to contain either 10 numbers or 13 numbers (in a sequence without characters)

I have:

<... ValidationRegEx="\d{13}" /> 

which works fine, but when I want to add a mask of ten, it breaks:

 <... ValidationRegEx="\d{13} | \d{10}" /> 

Any ideas?

+7
source share
3 answers

This is what worked for me:

 < ... RegEx="\b\d{10}\b|\b\d{13}\b" ... /> 

This means "find the whole word with 10 digits or find the whole world with 13 digits."

the \ b in front and behind the regular expression means finding the whole word.

Check out this site that helped me answer my own question:

http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial

0
source

I'm thin, spaces should be removed, for example:

 ValidationRegEx = "\d{13}|\d{10}" 

Otherwise, the space characters become part of the line you are matching (i.e. 13 digits followed by a space, or a space followed by ten digits).

You can also try to simplify the expression as follows:

 ValidationRegEx = "\d{10}\d{3}?" 

(ten plus three optional digits required).

+8
source
  β”Œβ”€β”€β”€β”€β”€β”¬β”€ 10 or 13 digits ↓ ↓ ValidationRegEx = "(?<!\d)\d{10}\d{3}?(?!\d)" ↑ ↑ β”‚ └─ negative lookahead to ensure β”‚ there is no other digit ahead β”‚ └─ negative lookbehind to ensure there is no other digit behind 
0
source

All Articles