javascript - Using ng-required with model's value in AngularJS -


i'm trying validate form. in 1 field, have validate null & it's value. how can this?

by way, don't write function on controller.

<form name="frm"> <input type="text" ng-model="mymodel" ng-required="mymodel != '' || mymodel != undefined || mymodel != 'xxx'" /> <button ng-disabled="frm.$invalid" >send</button> 

you can't ng-required because checks if value entered or not. in case can use ng-required cover statements: mymodel != '' || mymodel != undefined. , if want check mymodel value isn't 'xxx' should use ng-pattern directive. appropriate regex case should be: /^(xxx.+|(?!xxx).*)$/.

<form name="frm">    <input type="text" ng-model="mymodel" ng-pattern="/^(xxx.+|(?!xxx).*)$/" ng-required="" />    <button ng-disabled="frm.$invalid" >send</button> </form> 

check documentation directives components input.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -