Rana Ali
Rana Ali

Reputation: 71

angularjs custom validation on input type="text"

<section class="col col-6">
   <label class="input">
      <i class="icon-append fa fa-building"></i>
      <input type="text" ng-model="customer.Name" name="customerName" placeholder="Customer Name" required>
      <span style="color:red" ng-show="myForm.customerName.$dirty && myForm.customerName.$invalid">
         <span ng-show="myForm.customerName.$error.required">Name Required</span>
      </span>
   </label>
</section>

How can i implement custom validation on it? m applying angularjs validation it works fine but I want custom valuation on this tag. I want user insert only alphabets in this textbox.

Upvotes: 0

Views: 216

Answers (1)

Bohuslav Burghardt
Bohuslav Burghardt

Reputation: 34776

Use ngPattern directive and provide appropriate regular expression:

<input ng-pattern="/^[a-zA-Z]*$/" />

Upvotes: 1

Related Questions