Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

am using the patterns like "/[a-zA-Z0-9][^\s]/" and "/\s/" but no one is working. can you give any solution for this "ng pattern for input tag and which allows oly alphanumeric but it does not allow spaces in the input field ".

share|improve this question

2 Answers 2

Try the following pattern: /^\s*\w*\s*$/

<script>
   angular.module('textInputExample', [])
     .controller('ExampleController', ['$scope', function($scope) {
       $scope.text = 'guest';
       $scope.word = /^\s*\w*\s*$/;
     }]);
 </script>
 <form name="myForm" ng-controller="ExampleController">
   Single word: <input type="text" name="input" ng-model="text" ng-maxlength="5"
                       ng-pattern="word" required ng-trim="">

Plunkr link

share|improve this answer

Please see here http://jsbin.com/ruqet/1/edit

   <form name="myform">
        <input type="text" ng-model="val" ng-pattern="/^[a-zA-Z0-9]*$/" name="abc"/>
        <br/>
        <span ng-show="myform.abc.$error.pattern">Please use numbers letters only</span>
      </form>
share|improve this answer
    
But it does not display error message when we enter space into the text box. This is for alphanumeric [a-zA-Z0-9] working but the input field does not accept spaces. –  swapna Oct 9 '14 at 4:28
    
@swapna you can add required please see updated jsbin jsbin.com/ruqet/2/edit –  sylwester Oct 9 '14 at 8:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.