-1

I am using a form to get user details. In my name input I want only alphabetic characters, spaces and apostrophe. So I created the form input like

<input placeholder="FULL NAME" type="text" ng-model="customer.name" ng-pattern="/([a-zA-Z'\s])+/" ng-required="true">

However in my form if I give input hyphen or underscore characters it is still taking as a valid input. What I am doing wrong?

Muhammad Raihan Muhaimin
  • 5,559
  • 7
  • 47
  • 68
  • see this answer. http://stackoverflow.com/questions/22952077/why-is-angularjs-ng-pattern-not-working-with-the-following-regexp/25484623#25484623" – Ved Jul 10 '15 at 10:28

1 Answers1

1

Hey all so the solution for my problem was just to change

ng-pattern="/([a-zA-Z'\s])+/" 

to

ng-pattern="/^([a-zA-Z'\s])+$/"

So now input element looks like this

<input placeholder="FULL NAME" type="text" ng-model="customer.name" ng-pattern="/^([a-zA-Z'\s])+$/" ng-required="true">
Muhammad Raihan Muhaimin
  • 5,559
  • 7
  • 47
  • 68