473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help - regex validator expression not weeding out commas

i am trying to validate a field for a double, but not allow commas

the regex specifies

any number of whole number digits [0-9]*
no comma [^,]*
an optional decimal point .?
and any number of digits after the decimal [0-9]*

the whole thing looks like this:
[0-9]*[^,]*.?[0-9]*

what am i doing wrong?

as is i am having to use a range validator for double, and give it 0
as the minimum, but i would prefer the regex.

also, can the regex validator be used to "clean" out bad values,
meaning as long as SOME valid characters are in there, it doesn't
generate an error, but when the form is posted, unwanted chars
such as dollar sign and comma are ignored and not posted?

thanks in advance
Nov 18 '05 #1
3 2061
First you can try to find a regular expression that suits your needs on
net (for example http://www.regexlib.com/)

Your expression means
any decimal
fallowed by
anything except ','
fallowed by
any character (. means any character if you want the character '.' you
must escape it '/.')
fallowed by
any decimal

So the expression will also match something like 1232asd3218238

For a simple double the following expression should be enough:
^[0-9]*\.?[0-9]*$

this will match any of the fallowing:
23.89
1232
23.
..67

Be aware of the localization problems. I think that using a Compare
validator would be better.

For the additional characters you can let the validator expression be a
little more 'flexible' and remove the unwanted characters on the server.

Mad Scientist Jr wrote:
i am trying to validate a field for a double, but not allow commas

the regex specifies

any number of whole number digits [0-9]*
no comma [^,]*
an optional decimal point .?
and any number of digits after the decimal [0-9]*

the whole thing looks like this:
[0-9]*[^,]*.?[0-9]*

what am i doing wrong?

as is i am having to use a range validator for double, and give it 0
as the minimum, but i would prefer the regex.

also, can the regex validator be used to "clean" out bad values,
meaning as long as SOME valid characters are in there, it doesn't
generate an error, but when the form is posted, unwanted chars
such as dollar sign and comma are ignored and not posted?

thanks in advance


--
____________________
www.bloomfield.as.ro
Nov 18 '05 #2
thanks for the reply, and the web site

i have a question, what are the ^ and $ for?
For a simple double the following expression should be enough:
^[0-9]*\.?[0-9]*$

Nov 18 '05 #3
^ specifies the beginning of the string and $ specifies the end of the
string
See msdn 'Regular Expression Language Elements' for an extensive
description of regular expressions used in .NET
Mad Scientist Jr wrote:
thanks for the reply, and the web site

i have a question, what are the ^ and $ for?

For a simple double the following expression should be enough:
^[0-9]*\.?[0-9]*$


--
____________________
www.bloomfield.as.ro
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
4
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
4
by: | last post by:
Here is an interesting one. Running asp.net 2.0 beta 2. I have a regular expression used in a regex validator that works on the client side in Firefox but not in IE. Any ideas? IE always reports...
5
by: John | last post by:
I am new in Regular Expression. Could someone please help me in following expression? 1. the string cannot be empty 2. the string can only contains AlphaNumeric characters. No space or any...
2
by: zdrakec | last post by:
I need to be able to do a Regex.split on a csv file ignoring the comma if it is inside a single quote. I have the regular expression working in the RegexDesigner tool, but when I use it within...
5
by: Jeff | last post by:
....hoping someone can help someone still new to vb.net 2005 with something new to him. ....been successfully using the regular expression validators from the toolbox, but now I have need to do...
2
by: Mick Walker | last post by:
Hi All, I would like to know how I can limit users to only registering usernames which have alphanumberic characters and one underscore. From what I understand is I can use a regex to do this....
4
by: =?Utf-8?B?bWFnZ2ll?= | last post by:
hi, I need some help with a reg. expression. I have a comma delimited file with quotes. Not every field has quotes, only some. This is a sample of my file:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.