Reputation: 327
I'm trying to validate a phone number using the ngMessages and ngMessage directives, but I am facing two problems:
I want the "Invalid Input" to be shown as soon as the user starts typing, and not only after the pattern is met.
I don't understand what is wrong with my code, so I'd appreciate any help.
<form name="PhoneForm">
<div>
<md-icon md-svg-src="icons/ic_phone_48px.svg"></md-icon>
<md-input-container>
<label>Phone</label>
<input ng-model="contactPhone" name="PhoneInput" required ng-pattern="/^(05){1}[0-9]{8}$/"/> <!-- i.e 05x-xxxxxxx -->
<div ng-messages="PhoneForm.PhoneInput.$error" ng-if="PhoneForm.PhoneInput.$dirty">
<div ng-message="required">This field is required!</div>
<div ng-message="pattern">Invalid Input!</div>
</div>
</md-input-container>
</div>
Thank you
Upvotes: 1
Views: 146