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 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
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
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
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
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>) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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()...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |