0

I am writing an app with AngularJS 1.5. I am trying to write a feature where the user can verify their password in the app and I am using ng-messages to try to validate the form.

My from has 2 fields: password and confirm password. The 2 validation conditions are: both passwords are required and the passwords must match.

The problem I have is the pattern match fails for a few special characters. It fails for the dollar sign but not all special characters. I need it to work for all characters.

Here is my JSFiddle: http://jsfiddle.net/aubz88/gm0obnqf/69/

A code snippet:

  <div>
    <label 
      class="item" 
      ng-class="{ 'has-error' : vm.verifyPassword.password.$invalid && (vm.verifyPassword.$submitted || vm.verifyPassword.$dirty) }">
    <span class="input-label">Password</span>
    <input
      id="password"
      type="password"
      name="password"
      ng-model="vm.data.password"
      placeholder="password"
      required>
    </label>
  </div>
user1261710
  • 2,539
  • 5
  • 41
  • 72

1 Answers1

1

The problem is this line in your JSFiddle, you pass vm.data.password (as a string) to ng-pattern.

ng-pattern="vm.data.password"

According to document of Arguments section of ngPattern https://docs.angularjs.org/api/ng/directive/ngPattern#ngPattern-arguments:

"AngularJS expression that must evaluate to a RegExp or a String parsable into a RegExp, or a RegExp literal."

So AngularJS parses your input into regular expression, that's why some symbols failed, for example $ (dollar sign), as $ is a reserved keyword in regular expression.

koo
  • 171
  • 1
  • 11