Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angular js使用正则表达式显示_Javascript_Angularjs_Html - Fatal编程技术网

Javascript 使用angular js使用正则表达式显示

Javascript 使用angular js使用正则表达式显示,javascript,angularjs,html,Javascript,Angularjs,Html,我有两个图像,基于输入正则表达式模式,我想一次显示一个图像 我的代码是 <input type="password" ng-model="password" placeholder="Enter Password"/> <img src="../close.png" ng-show="password != [a-z]"/> <img src="../right.png" ng-show="password == [a-z]"/> 这类功能的解决方案是

我有两个图像,基于输入正则表达式模式,我想一次显示一个图像

我的代码是

<input type="password" ng-model="password" placeholder="Enter Password"/>

<img src="../close.png" ng-show="password != [a-z]"/>
<img src="../right.png" ng-show="password == [a-z]"/>

这类功能的解决方案是什么。

使用以下选项:

<input type="password" ng-model="password" placeholder="Enter Password"/>
<img src="../close.png" ng-if="password != [a-z]"/>
<img src="../right.png" ng-if="password == [a-z]"/>

ngShow
ngIf
指令之间的区别在于,ngShow将只隐藏/显示元素,而该元素存在于DOM中。而如果不使用,ngIf将从DOM中删除元素。

$scope.checkPassword=checkPassword;
功能检查密码(输入){
var onlySmallLetters=/^[a-z]+$/
仅返回ysmalletters.test(输入);
}

var myApp=angular.module('myApp',[]);
myApp.controller('controller',function($scope){
$scope.password;
$scope.hasLowerCase=函数(str){
$scope.lowerStr=angular.lowercase(str);
如果($scope.lowerStr==str&&str!=null&&str!=''){
返回true;
}
否则{
返回false;
}
}
});



我想下面是您需要的

理想情况下,输入元素应该基于模式进行验证,并根据模式结果向用户显示相应的消息

因此,与签入
img
标记不同,我更愿意使用ng模式检查输入本身,并根据输入的有效性显示相应的img

参见实施
angular.module('myApp',[]);
角度.module('myApp').controller('MyController',MyController);
函数MyController($scope){
};



ng if=“Boolean”你有完整的代码吗?我的意思是tes(值)放上你的完整代码,这是为了帮助你不做你自己的代码不它不与模式一起工作。模式是任何小写字符。此代码可以工作,但如果先放大写,然后再放小写,则此代码不工作。您想做什么?当您使用小写字母后一个是您想要的,它的工作。但是如果你想要一个大写字母后面加一个小写字母后面,它就不适用于这个,你的问题也不是那个。