Question: I have :

```
^-?[0-9]\d*(\.\d+)?$

```

But need it to allow only up to 3 decimal places. So allowed values are:

```
+10.123

-10.123

10.123

10

+10

-10

10.1

10.12

```

Not allowed:

```
10.1234

10.123%

```

Advice / suggested expression mods appreciated.

Thanks in advance.

Answer: 
```
 ^[+-]?\d+(\.\d{1,3})?$

```

Explanation:
[![enter image description here](https://i.stack.imgur.com/Kbgex.png)](https://i.stack.imgur.com/Kbgex.png)

See it here: <https://www.debuggex.com/r/BbCBL5pQWLxsD4a6>

```
^ asserts position at start of a line
   Match a single character present in the list below [+-]?
     ? Quantifier — Matches between zero and one times, as many times as possible, 
                    giving back as needed (greedy)
     +- matches a single character in the list +- (case sensitive)
   \d+ matches a digit (equal to [0-9])
      + Quantifier — Matches between one and unlimited times, as many times as possible, 
                     giving back as needed (greedy)
   1st Capturing Group (\.\d{1,3})?
     ? Quantifier — Matches between zero and one times, as many times as possible, 
                    giving back as needed (greedy)
     \. matches the character . literally (case sensitive)
     \d{1,3} matches a digit (equal to [0-9])
     {1,3} Quantifier — Matches between 1 and 3 times, as many times as possible, 
                        giving back as needed (greedy)
   $ asserts position at the end of a line

```

Explanation From: [<https://regex101.com/]>
`^[+-]{0,1}\d*?(\.{0,1}\d{0,3})?$` should work

see <https://regex101.com/r/P6DBrW/1/> for Explanation of the regexp