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

<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]"/>

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

最佳答案

$scope.checkPassword = checkPassword;
function checkPassword(input){
	var onlySmallLetters = /^[a-z]+$/
	return onlySmallLetters.test(input);
}

<input type="password" ng-model="password" placeholder="Enter Password"/>
<img src="../close.png" ng-if="checkPassword(password)"/>
<img src="../right.png" ng-if="!checkPassword(password)"/>

如果输入包含字母以外的任何字符,checkPassword方法将返回false
因此,仅当密码只有字母时才显示close.png,否则显示right.png

09-10 11:34
查看更多