1

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?

2 Answers 2

2

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+$/"> 
Sign up to request clarification or add additional context in comments.

3 Comments

Had no idea you could do it like that. Short and easy. Thanks!
I plan to, but can only do 10mins after posting the question :)
i think its almost 12 minutes :P
0

You could put

pattern="[A-Za-z]+" 

in the input tag to make the pattern match.

2 Comments

Why {28} and not * / +?
I was just giving an example but thanks I changed it to +.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.