Regular Expression for numbers like 12345.67, 123.45, 12.34, etc.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for a regular expression that would filter numbers in my vb.net
application. The integer part could have up to 5 digits and the fractional
part up to 2 digits.

I came up with the regex pattern of ^[0-9]{1,5}$ for Five decimal digits
or less but I couldn't finish the expression for the fractional part.

Thanks in adance.
 
dmbuso said:
I am looking for a regular expression that would filter numbers in my
vb.net
application. The integer part could have up to 5 digits and the fractional
part up to 2 digits.

I came up with the regex pattern of ^[0-9]{1,5}$ for Five decimal
digits
or less but I couldn't finish the expression for the fractional part.

Thanks in adance.

Sorry not close to VS right now but if you use reg exe lots this tool (free)
is what you need.

http://www.ultrapico.com/Expresso.htm

Hope this helps
LLoyd Sheen
 
dmbuso said:
I am looking for a regular expression that would filter numbers in my
vb.net
application. The integer part could have up to 5 digits and the fractional
part up to 2 digits.

I came up with the regex pattern of ^[0-9]{1,5}$ for Five decimal
digits
or less but I couldn't finish the expression for the fractional part.

Thanks in adance.

One that works for me (tested a few numbers):

^\d{1,5}(\.\d{1,2})?$

HTH,
Mythran
 
or you can try
^\d{1,5}(\.\d{1,2}){0,1}$
assuming no decimal pt allowed when no fractional part, also rejects any
extra dec pt
 
dmbuso said:
I am looking for a regular expression that would filter numbers in my
vb.net
application. The integer part could have up to 5 digits and the fractional
part up to 2 digits.

I came up with the regex pattern of ^[0-9]{1,5}$ for Five decimal
digits
or less but I couldn't finish the expression for the fractional part.

Thanks in adance.

^(?<Int>\d{1,5})(?<Dec>(?<Pt>[\.,])\d{1,2})?$

The above will handle 1-5 digits followed by either a . or , (intl you
know). Then up to 2 digits.

It will return the following for the value (12123,23)
Int = 12123
Dec = ,23
Pt = ,

Hope this helps
Lloyd Sheen
 
Back
Top