Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
| Search | Today's Posts | Mark Forums Read
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services 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 August 8th, 2003, 12:26 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default .NET Regular Expressions

I'm having two little problems with my first attempt at regular expressions - I would like the following to determine whether user input is a certain type of numeric: 7 digits possibly followed by a decimal point and possibly 2 post decimal digits:
 "^[0-9]{0,7}\.?[0-9]{0,2}$"

1. How do I specify that the 2 digits after the decimal are only appropriate if there indeed is a decimal? Currently, it allows a 9-digit number without a decimal.
2. Can I substitute variables for the 7 and 2? I tried and can't make it work - are there some special delimiters used to surround variables? e.g., I want to do something like:
 "^[0-9]{0,iPreDecimalDigits}\.?[0-9]{0,iPostDecimalDigits}$"

Thanks,
Dave Doknjas

 
Old August 8th, 2003, 05:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

try the following :

/^(\d{7})|(\d{7}.\d{0,2))$/

This will allow either a 7 digit number or a 7 digit number, decimal point, and then 2 digits.
 
Old August 8th, 2003, 07:10 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Greg!
I made a slight change to get it to work:
^(\d{0,7}|\d{0,7}\.\d{0,2})$






Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Regular Expressions in ASP.NET/VB.NET toddw607 ASP.NET 1.0 and 1.1 Basics 0 February 5th, 2008 04:26 PM
Do I need regular expressions..? ypomonh XSLT 2 May 20th, 2007 05:09 PM
Help with Regular Expressions WestRowOps Other Programming Languages 1 May 18th, 2007 05:34 AM
Regular Expressions mega Beginning PHP 1 February 5th, 2007 05:31 PM
Regular expressions on C# hideway C# 2 November 27th, 2006 05:08 PM





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