Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need validaton expression for the following

Posted on 2011-05-08
4
Medium Priority
?
197 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:paradigm_IS
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:x77
ID: 35716542
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
 
LVL 15

Expert Comment

by:x77
ID: 35716615
for common regular expression validations:
http://msdn.microsoft.com/en-us/library/ff650303.aspx

Try: ^(-)?\d+(\.\d)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35745785
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 35745791
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question