Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2006, 05:04 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default regular expression for number upto 2 decimal place

Hi all,

I am using regular expression validator for validating number upto 2 decimal places. I am using following following regular expression for validation.

\d{1,3}.\d{0,2}

This works fine for numbers like 1.23 or 1.00. But if I enter 1 or any integer, the expression is not accepting it.

I want regular expression which will accept interger input as well as number upto 2 decimal places.

Please help.



 
Old April 5th, 2006, 07:19 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Make the second part of your RegEx conditional.

"The one language all programmers understand is profanity."
 
Old April 5th, 2006, 08:24 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Will you please tell me how to make it conditional?

 
Old July 31st, 2008, 11:23 AM
Registered User
 
Join Date: Jul 2008
Location: Noida, UP, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mail2amitchawla
Default

Hi,

You can make second part optional if your second part preceeds by a question mark "?".

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

Best Regards,
Amit Chawla.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Number with 2 decimal places only pallone SQL Server 2000 4 July 3rd, 2007 07:29 AM
round up a decimal number semooth VB How-To 3 October 4th, 2005 02:33 PM
Decimal place problem...ROUND function! kuku SQL Server 2000 9 July 9th, 2005 05:50 PM
Regular Expression that not let number zero Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 December 28th, 2004 01:09 AM
number of decimal? hosefo81 PHP How-To 1 February 11th, 2004 02:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.