php - Regex for numbers like 1.1 -


i trying make regex allow following

1 1.1  9.9 9 

but not allow 1.11 or 9.97 or 9,7

can me?

i tried '/[0-9]+(\.[0-9]?)?/' still allows 1.11

your regex match pattern describe fails exclude pattern not want match. 1.1 part in 1.11 matches regex. exclude 1.11 can add regex string has end after first decimal: ^\d+(\.\d)?$.

\d matches digit; have escape . because otherwise matches character; , $ means 'end of string'. quick reference can check this.

quite logically problem happens @ start of regex, yours surely matches a1.1. special character ^ means 'start of string'.

a regex matching needs be:

^\d+(\.\d)?$ 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -