Whats wrong with this regular expression?

C

COHENMARVIN

I am trying to use an regularexpression validator to match floating
numbers.
My expression doesn't work.
Here it is:
ValExpression = "(0|[1-9][0-9]*|[1-9][0-9]*\.[0-9]*|0\.[0-9]*)"
The \. is supposed to match the decimal point, but entering any
decimal point in a number doesn't work.
Any help is appreciated.
-- Marvin
 
P

Peter Blum

I have two thoughts.

1. The CompareValidator can validate decimal numbers by setting its Operator
property to DataTypeCheck and Type=Decimal.

2. If you are assigning ValExpression programmatically using C#, the \
character is a special symbol. Always use two \ characters like this:
ValExpression = "(0|[1-9][0-9]*|[1-9][0-9]*\\.[0-9]*|0\\.[0-9]*)"

or use the @ symbol before the string to override the special characters:

ValExpression = @"(0|[1-9][0-9]*|[1-9][0-9]*\.[0-9]*|0\.[0-9]*)"

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top