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

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.
 
L

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.

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
 
M

Mythran

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
 
G

GS

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
 
L

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.

^(?<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top