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

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -