Need validaton expression for the following

I have a textbox and have assigned a regular expression validator to it.
Basically I need to validate that the user enters only one decimal place. (i.e. only one digit after the decimal)

Some example valid scenarios are as follows:

1) 1.2
2) 0
3) .4
4) 1
5) '' (empty space or blank)

Also, if anyone could provide a good site which teaches how to build validation expressions, that would be helpful.
paradigm_ISAsked:
Who is Participating?
 
käµfm³d 👽Commented:
Correction to the above patterns (I forgot to escape the dot):

^(?:\s*|\d*(?:\.\d)?)$

Open in new window


^(?:\s*|-?\d*(?:\.\d)?)$

Open in new window

0
 
x77Commented:
I do´nt like regular expresions to validate numbers.
I use DataBinding, with format.
Using "N1", validates to a decimal place and also shows thousand separator.
You can also enter exponential values:  1.23e4 ->1230
it supports globalization (decimalpoint character).
It do correct validation for negative sign....
0
 
x77Commented:
for common regular expression validations:
http://msdn.microsoft.com/en-us/library/ff650303.aspx

Try: ^(-)?\d+(\.\d)
0
 
käµfm³d 👽Commented:
x77's pattern won't handle the blank, the single digit, or the decimal with no leading digit, unfortunately. Try the following:

^(?:\s*|\d*(?:.\d)?)$

Open in new window


If you need the negative, x77's approach should work:

^(?:\s*|-?\d*(?:.\d)?)$

Open in new window


Also, if anyone could provide a good site which teaches how to build validation expressions, that would be helpful.

Open in new window

I prefer www.regular-expressions.info . Also, there is Expresso, a .NET regular expression tool, which you can use to build regular expressions. It has a feature that explains the regular expression.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.