\ |] {1}...">

Double-quoted regex pattern not working correctly

I have a validation of an ng template for a regular expression ^ [^ \ ./: * \? \ "<> \ |] {1} [^ \ /: * \? \" <> \ | ] {0,254} $, which basically checks for invalid characters in the file path and limit. but when i have ng template specified as

 ng-pattern = "^[^\\\./:\*\?\"<>\|]{1}[^\\/:\*\?\"<>\|]{0,254}$"

The ng pattern shows the regular expression in the wrong way. any help in achieving this correctly

+4
source share
3 answers

, " \\.

, , {{...}} ng-pattern.

, \ 4 .

var app = angular.module("app",[]);

app.controller("FormCtrl", function($scope) {
  $scope.regex = "/^[^\\\\./:*?\"<>|][^\\\\/:*?\"<>|]{0,254}$/";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
    <form name="theForm" ng-controller="FormCtrl" novalidate>
        <input type="text" name="filename" placholder="filename" ng-model="filename" ng-pattern="{{regex}}" required />
        <div class="error"
                     ng-show="(theForm.filename.$dirty || attempted) && theForm.filename.$invalid">
                  <small class="error text-danger"
                         ng-show="theForm.filename.$error.required">
                    Please enter a file name.
                  </small>
                  <small class="error text-danger"
                         ng-show="theForm.filename.$error.pattern">
                    Please enter a valid file name.
                  </small>
                </div>
    </form>
</div>
Hide result
+3

"" ng-, . "" , :

<input type="text" ng-pattern="/^[^"']+$/" />

+1

\&quot; ".

+1
source

Source: https://habr.com/ru/post/1618934/


All Articles