I want to do like this : 3.40 and not more than 3 characters and one dot:
<md-input-container class="md-block">
<label>Marks/CGPA</label>
<input type="text" name="education.cgpa" ng-model="education.cgpa"
ng-pattern="/^[0-9]{0,4}$/">
<div class="input-validation" ng-show="educationSaveForValidate['education.cgpa'].$error.pattern">
Insert valid CGPA
</div>
</md-input-container>
How can I allow only 3 digits and one dot in Regular Expression?
You may use a single regex like
or - to allow an empty string:
You may also move the length check out of the regex:
Details
^- start of string(?!.{5})- a negative lookahead that fails the match if there are any 5 chars in the input string\d*- 0+ digits\.?- an optional.\d*- zero or more digits (if\d+is used, then 1 or more digits)$- end of string.To disallow any leading/trailing spaces, add
ng-trim="false".