Reputation: 2765
So I have an input with the type text
:
<div class="row">
<div class="form-group">
<input type="text" class="form-control col-sm-12" id="last-name-reservation-form" placeholder="Last name" required>
</div>
</div>
How would I be able to filter on the input characters, such that it only takes text and not numbers? Sort of similar to how type="number"
only allows numbers to be input.
Do I have to make something in the controller or can it be done directly in the .html?
Upvotes: 1
Views: 53
Reputation: 24
You could put
pattern="[A-Za-z]+"
in the input tag to make the pattern match.
Upvotes: 0
Reputation: 222582
You can just use ng-pattern
For restricting only alphabets,
<input type="text" ng-model="myText" name="inputName" ng-pattern="/^[a-zA-Z]*$/" >
For restricting only numbers,
<input type="text" ng-model="myText" name="inputName" ng-pattern="/^\d+$/">
Upvotes: 2