ng-pattern

Conditional ng-pattern in angular js

心不动则不痛 提交于 2019-12-07 01:26:28
问题 Is there a way to achieve conditional ng-pattern in angularjs ng-pattern="(myForm.exipration.$dirty ? ('/^\d{2}[/]\d{4}$/') : '')" i tried like above, but does not help. 回答1: Markup <input ... ng-pattern="handlePatternPassword"> Controller $scope.handlePatternPassword = (function() { var regex = /^[A-Za-z0-9!@#$%^&*()_]{4,20}$/; return { test: function(value) { if ($scope.user.isLogged) { return (value.length > 0) ? regex.test(value) : true; } else { return regex.test(value); } } }; })();

Conditional ng-pattern in angular js

三世轮回 提交于 2019-12-05 04:24:39
Is there a way to achieve conditional ng-pattern in angularjs ng-pattern="(myForm.exipration.$dirty ? ('/^\d{2}[/]\d{4}$/') : '')" i tried like above, but does not help. Jonatas Walker Markup <input ... ng-pattern="handlePatternPassword"> Controller $scope.handlePatternPassword = (function() { var regex = /^[A-Za-z0-9!@#$%^&*()_]{4,20}$/; return { test: function(value) { if ($scope.user.isLogged) { return (value.length > 0) ? regex.test(value) : true; } else { return regex.test(value); } } }; })(); From https://stackoverflow.com/a/18984874/4640499 . Mathieu Allain The following worked for me

ng-pattern with regex having double quotes does not escape correctly

☆樱花仙子☆ 提交于 2019-12-01 18:03:56
问题 I have a ng-pattern validation for a regex of ^[^\./:*\?\"<>\|]{1}[^\/:*\?\"<>\|]{0,254}$ which basically tests the invalid chars in filepath and teh limit. but when i have the ng-pattern specified as ng-pattern = "^[^\\\./:\*\?\"<>\|]{1}[^\\/:\*\?\"<>\|]{0,254}$" , the ng-pattern shows the regex in an incorrect way. any help on achieving this correctly 回答1: First of all, your regex contains too many escaping symbols, while you only need to escape the " here and \\ . Then, to match a " inside

How to validate email id in angularJs using ng-pattern

送分小仙女□ 提交于 2019-11-27 00:13:18
Am trying to validate an Email id field in angularJs using ng-pattern directive. But am new to AngularJs. I need to show an error message as soon as the user enters the wrong email id. The code which I have below is am trying to solve. Help me out with using ng-pattern for getting the proper result. <script type="text/javascript" src="/Login/script/ang.js"></script> <script type="text/javascript"> function Ctrl($scope) { $scope.text = 'enter email'; $scope.word = /^[a-z]+[a-z0-9._]+@[a-z]+\.[a-z.]{2,5}$/; } </script> </head> <body> <form name="myform" ng-controller="Ctrl"> <input type="text"