Ng-pattern that allows decimal relationships

I have ng-pattern

one that checks for a ration like 4: 6 like below:



I want to also check if decimal numbers will be entered as solders along with the above check. Example: 5.4: 7.1 I trid, giving ng-pattern




But don't run the check. Please suggest me where I go wrong.


source to share

1 answer

Yours is ^(\.[0-9]{1,2}+):(\.[0-9]{1,2}+)$

not a valid pattern in JS as the constraint quantifier {min,max}

cannot be executed with +

(no adventive quantifiers are supported by the JJ regex engine). Even if you remove the pros and use ^(\.[0-9]{1,2}):(\.[0-9]{1,2})$

, the pattern will match strings like .1:.3

or .34:.45

and will not allow 3:45

(dots must be required).

Use the following regex if you want to allow values โ€‹โ€‹such as .5




See demo regex .

Alternatively, you can use



to resolve numbers with a non-empty integer part. See this regex demo .



All Articles