Home > OS >  Need help to build regular expressions C# ASP.NET Core
Need help to build regular expressions C# ASP.NET Core

Time:10-31

I want to write a RegEx to validate a text line on some conditions. Those are -

  1. 1st 6 characters must be number
  2. Then 3 characters must be Uppercase letter
  3. Then other characters are decimal number, but max length in 15 (Decimal part). Decimal part can have comma (,) in it and 2 decimal point after that comma.

I am trying to build and ended like this:

^\d{6}[A-Z]{3}\d{1,15}[\d,]{0,3}$

Here is some example

123456ABC124                  valid
123456BCD123456789123,00      valid
090929BDT888,00               valid
123456BCD1234567891234,00     invalid

It works fine but I can't specify decimal length can't be more than 15

CodePudding user response:

following what you say, the solution is:

^\d{6}[A-Z]{3}(?:\d{1,15}$|\d{1,14},$|\d{1,13},\d$|\d{1,12},\d\d$)
  • Related