Any one use AngulerJS Validation on TextBox. So that only enter alphabets.
相关问题
- angularJS: ui-router equivalent to $location.searc
- Separate AngularJS Controllers Into Separate Files
- Angular ngAnimate not working first time on page l
- Ionic Spinner not showing up
- Upload file to Google Cloud Storage using AngularJ
相关文章
- Passing variable through URL with angular js
- Watch entire object (deep watch) with AngularJS
- Angular ng-if change span text
- Can ng-show directive be used with a delay
- AngularJS $routeParams vs $stateParams
- Multiple parameters in AngularJS $resource GET
- How to set class/style of accordion heading in Ang
- PUT to S3 with presigned url gives 403 error
I guess all the other answers using ng-pattern are correct but just to mention, the use of
ng-model
is compulsory withng-pattern
.The complete input can be:
This will accept the alphabets and the spaces only.
Depending on what you want:
Alphabets and blankspace:
Alphabets no blankspace:
If you don't want to use ng-pattern for whateever reason, you can also add validating functions to the ng-modal-controller that is set up on your textbox, specifically to the formatters and parsers arrays. A good description of how to do this is here: http://www.benlesh.com/2012/12/angular-js-custom-validation-via.html. Another alternative is to use a published directive to achieve the same purpose, I haven't used this one myself but it seems legit: http://www.brentmckendrick.com/code/xtform/
There is a directive called
ng-pattern
it allows to use regular expressions to indicate which are the allowed values.It can be used like this:
add this to your input