0

As per my requirement i need to check three conditions using regular expression.

'Find the dot position

 dotPos = InStr(editFormat, ".")

'Find whole number of digits

 wholeNum = Left$(editFormat, dotPos - 1)

'Find decimal number of digits

decNum = Mid(editFormat, dotPos + 1, strLen - dotPos - 1)

regularExp = "^[-]{0,1}[0-9]{0," & wholeNum & "}\" & DecSep & "[0-9]{0," & decNum & "}$"

Here, i need to validate

1) whole value(Before dot)

2) decimal value(After dot)

3) whole length of the input.

wholeNum = 30

decNum  = 20

Ex: The value is 123456789012345678901234567890.12345678901234567890

As per my code this two conditions are working Fine.

But i need to add one more condition is Total length should be 40.

Ex: Possible inputs for your example: ( (30.10) or (20.20) or (25.15) )

1) 123456789012345678901234567890.1234567890 (Total should be 40)

2) 12345678901234567890.12345678901234567890

3) 1234567890123456789012345.678901234567890

How to add that condition in my code.

Thanks.

Srb1313711
  • 2,017
  • 5
  • 24
  • 35
prakasam k
  • 89
  • 3
  • 11

1 Answers1

0

I'd use a lookahead assertion:

regularExp = "^" & "(?=.{40}$)" & "[-]{0,1}[0-9]{0," & wholeNum & "}\" & DecSep & "[0-9]{0," & decNum & "}$"

assuming you're counting including the dot.

Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145