html - How to validate text box in Angular js -


i have text box , search button in ui. want validate numbers should entered on button click.

i didn't use in form(i got know lot of ways validate form control). i've designed it(independent) in div.

so can pls guide me validate control in angular.

 <div id="srchbox">                 <p id="ptext">please enter movie id</p>                 <input type="text" class="form-control" placeholder="search" id="srchtxt" ng-model="_id">                 <button type="submit" class="btn btn-default" id="btnsrch" ng-click="search(_id)"><span class="glyphicon glyphicon-search"></span></button>         </div> 

use ngpattern directive.

from documentation

sets pattern validation error key if ngmodel value not match regexp found evaluating angular expression given in attribute value. if expression evaluates regexp object used directly. if expression string converted regexp after wrapping in ^ , $ characters. instance, "abc" converted new regexp('^abc$').

<input type="text" ng-model="myvariable" ng-pattern="" /> 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -