User123
User123

Reputation: 289

How to validate with regular expression and display error message in xeditable

I am using xeditable in my project.

I need to validate each and every field,

how to do validation using ng-pattern="/^[a-zA-Z ]*$/" and show error message if the input value does not match the pattern.

can any one guide me how can i proceed with this.

Fiddle

$scope.checkName = function(data) {
console.log("user.name.onbeforesave:", data)
if (data !== 'awesome') {
  return "Username should be `awesome`";
}

};

Upvotes: 0

Views: 557

Answers (1)

Beartums
Beartums

Reputation: 1350

Do you need to use ng-pattern? Can you not change the function to use the regexp?

This works:

 $scope.checkName = function(data) {
    console.log("user.name.onbeforesave:", data)
    if (!data.match(/^[a-zA-Z ]*$/)) {
      return "Only spaces and letters allowed";
    }
  }

Upvotes: 2

Related Questions