Question: ng-pattern that allows decimal ratios


ng-pattern that allows decimal ratios

Answers 1
Added at 2016-12-30 12:12

I'm having an ng-pattern that validates for a ration like 4:6 as shown below:


I want also to validate if decimal numbers are entered as rations along with the above validation.Example :5.4:7.1 I trid by giving ng-pattern as


But not triggering the validation.Please suggest me where I'm going wrong..

Answers to

ng-pattern that allows decimal ratios

nr: #1 dodano: 2016-12-30 12:12

Your ^(\.[0-9]{1,2}+):(\.[0-9]{1,2}+)$ is not a valid pattern in JS as the limiting quantifier {min,max} cannot be followed with + (no possessive quantifiers are supported by JS regex engine). Even if you remove the pluses and use ^(\.[0-9]{1,2}):(\.[0-9]{1,2})$, the pattern would match strings like .1:.3 or .34:.45 and would not allow 3:45 (dots would be obligatory).

Use the following regex if you want to allow values like .5:


See the regex demo.

Alternatively, you may use


to only allow numbers with non-empty integer part. See this regex demo.

Source Show
◀ Wstecz