Question: I have seen many links for floating point number validation but none of them for precision.

[only floating point number validation](https://stackoverflow.com/questions/12643009/regular-expression-for-floating-point-numbers)

I want the field to display error if the input is 1234.31 or . 
but not for 123.5555555 or .3433 or.9022. I need the rules to be specified to get 0 to 3 digit before decimal. I tried 

```
/^[^+-][0-9]{0,3}[.]?[0-9]{0,2}/

```

But it didn't work.

Answer: 
Use this regex:

```
/^\d{0,3}\.\d+/

```

But if you want to use your regex, modify it like this:

```
/^[^+-][0-9]{0,3}[.]?[0-9]+/

```

Your original regex didn't work because you were making it to match only up to 2 decimal places. `+` in regex means 1 or many.
You pretty much had it

```
/^([0-9]{0,3})?\.[0-9]+|[0-9]+$/

```

and use something like

```
if(!preg_match("^([0-9]{0,3})?\.[0-9]+|[0-9]+$/", $float)){}

```