You need to write a regular expression in C # only for numbers

I need a regular expression in C # for the following conditions that will validate a record in a text field:

I must contain either a 5-digit number or a 6-digit number. In the case of multiple entries, the numbers must be separated by a channel symbol without a space. Example: 34786 | 235652 | 12876

I tried the following regular expression that propyl does not work:

^\d{5,6}\|?\d{5,6}?$ ^[\d{5,6}+][\|?][\d{5,6}?]$ (^\d{5,6}$)|(^\d{5,6}\|?[\d{5,6}*]$) 

Please, help!

+4
source share
2 answers

Try the following:

 ^\d{5,6}(\|\d{5,6})*$ 
+4
source

This should work:

 ^[0-9]{5,6}(\|[0-9]{5,6})*$ 

Explaination:

^ = start of line

[0-9] = Any digit ( \d will work too)

{5,6} = Either 5 or 6 times

(...)* = Everything inside (), 0 or more times

\| = channel symbol

$ = End of line

Putting it together, this is โ€œthe beginning of a line, followed by 5 or 6 digits, followed by the [channel symbol, followed by 5 or 6 digits] 0 or more times, followed by the end of the lineโ€

+4
source

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


All Articles