Z
Z
zlodiak2020-04-29 17:04:13
Angular
zlodiak, 2020-04-29 17:04:13

How to check for some invalid characters?

There is a form consisting of one field. There is a set of characters that are allowed in this field. As a result, validation works without problems.

<form name='f1'>
  <input type="text" name="i1" ng-model="i1" required ng-pattern="/^[A-Za-z0-9!#$%&'()*+,-./:;<=>[email protected]^_`{|}~]+$/">
  <button ng-click="send(f1)">send</button>

  <errors>
    <error ng-if="f1.i1.$error.required && f1.i1.$touched">
      обязательное поле
    </error>

    <error ng-if="f1.i1.$error.pattern && f1.i1.$touched">
      недопустимый символ
    </error>
  </errors>
</form>


import HomeCtrl from './home.controller';
homeModule.controller('HomeCtrl', HomeCtrl);

function HomeCtrl($scope) {
  $scope.i1 = null;

  function send(f1) {
    console.log(f1)
  }
}


The problem is that I need to use a slightly different character set. Such:
ng-pattern="/^[A-Za-z0-9!"#$%&'()*+,-./:;<=>[email protected][\]^_`{|}~]+$/"


But I don't understand how to do it. There are problems with quotation marks, square brackets, and so on. However, escaping with \ does not help.

Please help me fix the code in the DEMO

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question