473,386 Members | 1,819 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,386 software developers and data experts.

Regular expression for 1 decimal

Hi,

I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok

1.11 --> not ok

I have this one [0-9]*\.?[0-9] but it does not do the .1 test
properly.

Thanks in advance.

Bas Jaburg
www.jaburg.com
Nov 16 '05 #1
5 13632
shouldn't the * be in the front?

*[0-9]\.[0-9]

meaning that there can be any number of values from 0-9, with none included,
then a ".", then one digit.

? - 1 or more
* - 0 or more
"bas jaburg" <bj*****@virtual-affairs.com> wrote in message
news:e6**************************@posting.google.c om...
Hi,

I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok

1.11 --> not ok

I have this one [0-9]*\.?[0-9] but it does not do the .1 test
properly.

Thanks in advance.

Bas Jaburg
www.jaburg.com

Nov 16 '05 #2
Wes
Hello bas,

If I understand you correctly you want a regular expression that will determine if a number has only one digit passed the decimal point.

What you have is close but it will also accept 1.11.

Try
^[0-9]*\.[0-9]$

This the ^ and $ force it to match the entire string.

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

Hi,

I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok
1.11 --> not ok

I have this one [0-9]*\.?[0-9] but it does not do the .1 test
properly.

Thanks in advance.

Bas Jaburg
www.jaburg.com


Nov 16 '05 #3
Doh, go with what wes said, it's been a few months since i looked at this.
;o)
"Dan =o)" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:e0*************@TK2MSFTNGP12.phx.gbl...
shouldn't the * be in the front?

*[0-9]\.[0-9]

meaning that there can be any number of values from 0-9, with none
included, then a ".", then one digit.

? - 1 or more
* - 0 or more
"bas jaburg" <bj*****@virtual-affairs.com> wrote in message
news:e6**************************@posting.google.c om...
Hi,

I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok

1.11 --> not ok

I have this one [0-9]*\.?[0-9] but it does not do the .1 test
properly.

Thanks in advance.

Bas Jaburg
www.jaburg.com


Nov 16 '05 #4
Hi bas! :O)

try this pattern :
//***
bool ret = Regex.IsMatch(".4", @"^\d*\.\d+?$");
//***

or this (more permissive) :
//***
string number = ".4";
bool ret = false;
double d = 0;
ret = double.TryParse(number, NumberStyles.Number, out d);
//***

--
Best Regards
Yanick Lefebvre

"bas jaburg" <bj*****@virtual-affairs.com> a écrit dans le message de
news:e6**************************@posting.google.c om...
Hi,

I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok

1.11 --> not ok

I have this one [0-9]*\.?[0-9] but it does not do the .1 test
properly.

Thanks in advance.

Bas Jaburg
www.jaburg.com

Nov 16 '05 #5
bas jaburg wrote:
I need to know the regular expression that checks the whether a
1-decimal number has been entered. Also it needs to ok if no trailing
number before the decimal dot has been entered

So:
1.3 --> ok
1.0 --> ok
.1 --> ok
11.1 --> ok

1.11 --> not ok


Use the "exactly <n>" quantifier and the word boundary delimiter:

Regex regex = new Regex(@"(\d*\.\d{1}\b)",
(RegexOptions) 0);

(Note that this will also capture the decimal part if your input string
is something like "abc.8".)
--
Take care,
Ken
(to reply directly, remove the cool car. <sigh>)
Nov 16 '05 #6

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

Similar topics

3
by: greenflame | last post by:
I am trying to find a regular expression that returns true in the following cases but no others. 2.0 2.4 2. 324.0e345 234e34 34.e-43 234.673
8
by: Ahmad A. Rahman | last post by:
Hi all, I have a problem constructing a regular expression using .net. I have a string, separated with comma, and I want to group the string together but, I failed to group a numeric character...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
6
by: bruce | last post by:
Hi. Not exactly a regex pro, but usually I know enough to get by. Here is my problem: I wrote a regex to edit a decimal number. you're allowed 1,2, or 3 digits before the decimal point, and...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
10
by: Mike9900 | last post by:
Hello, I need a regular expression to match a currency with its symbol, for example Pound66.99 must return 66.99 or Pound(66.99) or Pound-66.99 or -66.99Pound return -66.99 or any other...
11
by: Michael_Burgess | last post by:
Hi there, I'm using the following regex validator: ^\d{0,4}.?\d{0,2}$ This is to validate that a text box has 0-4 numbers, possible followed by a decimal point and possibly followed by 2...
4
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I am looking for a regular expression that would filter numbers in my vb.net application. The integer part could have up to 5 digits and the fractional part up to 2 digits. I came up with the...
10
by: venugopal.sjce | last post by:
Hi Friends, I'm constructing a regular expression for validating an expression which looks as any of the following forms: 1. =4*++2 OR 2. =Sum()*6 Some of the samples I have constructed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.