# Regular expression

T

#### Tony

Hello!

How do I write a regular expression that should have a pattern that except
the following format.
4
3.3
4.15
12
13.5
14.32

So valid format are either
1. One numeric figure as 4 above
2. One numeric figure and a decimal figure as 3.3 above
3. One numeric figure and two decimal figure as 4.15 above
4. Two numeric figure as 12 above
5. Two numeric figure and one decimal figure as 13.5 above
6. Two numeric figure and two decimal figure as 14.32 above

So how should the regular expression look like to accomplish this.

//Tony

B

El jueves, 17 de enero de 2013 11:28:30 UTC+1, Tony escribió:
Hello!

How do I write a regular expression that should have a pattern that except

the following format.

4

3.3

4.15

12

13.5

14.32

So valid format are either

1. One numeric figure as 4 above

2. One numeric figure and a decimal figure as 3.3 above

3. One numeric figure and two decimal figure as 4.15 above

4. Two numeric figure as 12 above

5. Two numeric figure and one decimal figure as 13.5 above

6. Two numeric figure and two decimal figure as 14.32 above

So how should the regular expression look like to accomplish this.

//Tony

Havent tested it, but should be something similar to this:

\d{1,2}(\.\d{1,2})?

T

#### Tony

Yes this work but one thing.
How should the regular expression be modified if I don't want to allow
format like 05.
I mean if you start with 0 and enter a second character this character but
be a dot

//Tony

El jueves, 17 de enero de 2013 11:28:30 UTC+1, Tony escribió:
Hello!

How do I write a regular expression that should have a pattern that except

the following format.

4

3.3

4.15

12

13.5

14.32

So valid format are either

1. One numeric figure as 4 above

2. One numeric figure and a decimal figure as 3.3 above

3. One numeric figure and two decimal figure as 4.15 above

4. Two numeric figure as 12 above

5. Two numeric figure and one decimal figure as 13.5 above

6. Two numeric figure and two decimal figure as 14.32 above

So how should the regular expression look like to accomplish this.

//Tony

Havent tested it, but should be something similar to this:

\d{1,2}(\.\d{1,2})?

B

El jueves, 17 de enero de 2013 14:07:13 UTC+1, Tony escribió:
Yes this work but one thing.

How should the regular expression be modified if I don't want to allow

format like 05.

I mean if you start with 0 and enter a second character this character but

be a dot

//Tony

El jueves, 17 de enero de 2013 11:28:30 UTC+1, Tony escribió:

Havent tested it, but should be something similar to this:

\d{1,2}(\.\d{1,2})?

I did google this one xD
(0|[1-9][0-9]?)(\.\d{1,2})?

T

#### Tony

El jueves, 17 de enero de 2013 14:07:13 UTC+1, Tony escribió:
Yes this work but one thing.

How should the regular expression be modified if I don't want to allow

format like 05.

I mean if you start with 0 and enter a second character this character but

be a dot

//Tony

El jueves, 17 de enero de 2013 11:28:30 UTC+1, Tony escribió:

Havent tested it, but should be something similar to this:

\d{1,2}(\.\d{1,2})?

I did google this one xD
(0|[1-9][0-9]?)(\.\d{1,2})?

If I use this regular expression (0|[1-9][0-9]?)(\.\d{1,2})?
I can still enter 05 for example which is not what I want.
I mean that if I enter a second character this
must be a dot not a figure ?

Have you some good example for this ?

//Tony

B

I did google this one xD

(0|[1-9][0-9]?)(\.\d{1,2})?

If I use this regular expression (0|[1-9][0-9]?)(\.\d{1,2})?
I can still enter 05 for example which is not what I want.

Try this
(0|([1-9][0-9]?))(\.\d{1,2})?

That should accept:
a) 0
b) ([1-9][0-9]?)

b) means digit from 1 to 9 with an optional second digit.

Think i was mising the parenthesis in b).