[英]check whether password match or not in primefaces + javascript
How can I check whether password match or not in primefaces + javascript? 如何在primefaces + javascript中检查密码是否匹配? I have used like this
我这样用过
function checkPass(){
var pass1 = document.getElementById('password');
var pass2 = document.getElementById('confirmPassword');
lert(pass2);
}
but getting null value! 但是获得空值! In primefaces I called like
onkeyup="checkPass(); return false;"
在primefaces中,我调用了
onkeyup="checkPass(); return false;"
I don't understand why are you using Primefaces and not take advantage of it's power... 我不明白你为什么使用Primefaces而不是利用它的力量......
There is a password
tag in primefaces with a match
attribute that matches the strings between two input passwords, also you can get a feedback if a password it's weaker or stronger: 在primefaces中有一个
password
标签,其match
属性与两个输入密码之间的字符串相匹配,如果密码较弱或较强,您也可以获得反馈:
<p:panel header="Match Mode">
<p:messages showDetail="true" autoUpdate="true"/>
<h:panelGrid columns="2" id="matchGrid">
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{passwordBean.password6}" feedback="true" match="pwd2" label="Password 1" required="true"/>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{passwordBean.password6}" feedback="false" label="Password 2" required="true"/>
</h:panelGrid>
<p:commandButton update="matchGrid" value="Save" />
</p:panel>
Please see this link: http://www.primefaces.org/showcase-labs/ui/password.jsf . 请参阅此链接: http : //www.primefaces.org/showcase-labs/ui/password.jsf 。 Since you haven't specified you Primefaces version, I have to tell you that this solution is for Primefaces 3.
由于您尚未指定Primefaces版本,我必须告诉您此解决方案适用于Primefaces 3。
Try this code 试试这个代码
onkeyup="checkPass(this.value)"
And javascript code: 和javascript代码:
function checkPass(text) {
var pass1 = document.getElementById('password');
if (text == pass1.value) {
alert('match');
return true;
} else {
return false;
}
}
To get the string value we have to use following code in JSF Primefaces like, 要获取字符串值,我们必须使用JSF Primefaces中的代码,例如,
var pass1 = document.getElementById('password_input');
var pass2 = document.getElementById('confirmPassword_input');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.