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(值)放上你的完整代码,这是为了帮助你不做你自己的代码不它不与模式一起工作。模式是任何小写字符。此代码可以工作,但如果先放大写,然后再放小写,则此代码不工作。您想做什么?当您使用小写字母后一个是您想要的,它的工作。但是如果你想要一个大写字母后面加一个小写字母后面,它就不适用于这个,你的问题也不是那个。