Reputation: 247
I'm trying to add control on primefaces' inputText.
I have this code :
<p:inputText onkeydown="charLimit(event);" />
<script type="text/javascript">
function charLimit(event) {
alert("test");
event.target.value = event.target.value.substr(0, 5);
}
</script>
It's working. But if I delete "alert('test')", it doesn't work. Do you have an idea ? Thanks
Edit : I still try to control the input with regexp. But when my regexp doesn't match, the input value is duplicate.
<p:inputText id="testtest" value="" maxlength="5" onkeyup="validerRegexp(event, this, '^[A-Z]{0,5}$');" />
function validerRegexp(event, that, regexp){
var expression = RegExp(regexp);
var valeur = verifierRegexp(expression, event.target.value);
if(valeur != null) {
that.value = event.target.value;
} else {
that.value = event.target.value.substring(0,event.target.value.length - 1);
}
}
function verifierRegexp(expression, valeur){
var resultat = null;
if(valeur != null && expression != null){
var tmp = valeur.match(expression);
if(tmp !=null && tmp.length > 0){
resultat = tmp[0];
}
}
return resultat;
}
Do you have an idea please ?
Upvotes: 0
Views: 255