I made a small js here
I also add the code to the Stack overflow snippet but for some reason it doesn't work to me
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.my_model = ''
$scope.my_regex = '/^[A-Za-z]+(\,[A-Za-z]+)*$/';
$scope.my_placeHolder = 'write something';
}
.invalid input[name=my_input]{
border: 2px solid red;
}
input[name=my_input] {
border: 2px solid blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="MyCtrl">
<form name="contentForm">
<input type="text"
name="my_input"
ng-class="{ 'invalid': contentForm['my_input'].$invalid }"
ng-model="my_model"
ng-pattern="{{my_regex}}"
placeholder="{{my_placeHolder}}">
</form>
</div>
I tried to use the code snippet but weren't working >,<
So, my goal is to edit the input border (let's make it red for purpose) if the input text doesn't pass the regex rule.
The regex should accept any comma separated string.
I tried a bunch of stuff, but I can't figure out what am i doing wrong.
UPDATE: REGEX EDITED