I see that a lot of people are using directives to solve this problem which I find annoying. While I like directives it feels like massive overkill.
I have an input
<input maxlength="4" type="text" id="CustomerNameKey" name="CustomerNameKey" class="form-control" ng-model="detail.customerNameKey" placeholder="Customer Name Key" required />
I thought the business requirement was just limit to 4 alphanumeric , so this code works great
maxlength="4"
However I cannot allow any number ( so only allowing a-z / A-Z )
Seems like I see
- angular documentation with it throwing out warning to the page, but it is not restricting the input I prefer to not allow more than 4 characters to be typed , and only alpha
- all these directive solutions seem crazy to me
- Any inline regex i can do?
As mentioned in the comments, the best approach is to use a directive. In fact, I just made one, you can see it in the jsFiddle
http://jsfiddle.net/HB7LU/28432/
EDIT:
HTML5 supports input checking in html
input
elements by use of thepattern
attribute, although it does not respond in real time and must be used with a submit. If this is the functionality you are looking for, you can get away with a simple element:more information can be found on the w3 page on the pattern attribute. Also noteworthy is the fact that this does not appear to be supported by safari