I play with Angular and am writing a Regex tester. The problem is that missing spaces are truncated when entering data. Jsfiddle example here :
So, when the page loads, I have RegEx "^ \ d + $". test ("123"), which results in "No match", but if you enter an additional top or end space in the "Candidate" field:
- Master and trailing spaces are removed from my variable
- As a result, the βMatchβ changes.
Here is my HTML:
<div id='ng:app' class='ng-app: myApp' ng-app='myApp'> <div ng-controller="Controller">{{addTodo2()}} <form novalidate class="simple-form">Pattern: <input type="text" ng-model="pattern" />Candidate: <input type="text" ng-model="candidate" /> <br />.{{candidate}}. <br>.{{candidate2}}.</form> </div> </div>
And here is the corresponding JavaScript:
function Controller($scope) { $scope.pattern = "^\\d+$"; $scope.candidate = " 123 "; $scope.candidate2 = " 123 "; $scope.addTodo2 = function () { var str = "Javascript is an interesting scripting language"; var re = new RegExp($scope.pattern, "g"); var result = re.test($scope.candidate); if (result) { return "Match22"; } else { return "No Match22"; }; }; } var myapp = angular.module('myApp', []);
source share