I'm new to angular and stumbled upon a validation problem in a form. Below is my input field and when I don't enter any value it show's as valid and also 'ng-valid' class is added to it even though I've defined minlength to be 5
<input id="name" type="text" placeholder="Name" ng-model="formdata.name" ng-minlength=5 />
It happens even in angular example - http://docs.angularjs.org/api/ng.directive:input
How can I resolve this?
You need to set the ngRequired
parameter as well. Without it the minlength parameter means that if the user has entered a value it must be at least 5 characters long, but it's ok to leave the field empty.
<input
id="name"
type="text"
placeholder="Name"
ng-model="formdata.name"
ng-minlength="5"
ng-required="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With