Well, I have a <p:inputText>
in primefaces, but I want know how can I allow only uppercase word and no special characters. Ex: Renato Calhaça = RENATO CALHACA
1
votes
2 Answers
2
votes
you can add in your inputText
<p:inputText onblur="this.value = this.value.toUpperCase();"/>
and in your css include at the end
.ui-inputtext, .ui-inputfield{
text-transform: uppercase;
}
UPDATE: if you use primefaces 6+ you can use the component p:keyFilter
http://www.primefaces.org/showcase/ui/input/keyFilter.xhtml
<p:inputText id="text1">
<p:keyFilter regEx="/[ABC]/i"/>
</p:inputText>
1
votes
"Renato".toUpperCase()
will convert the string to uppercase.
Take a look at java.text.Normalizer
for converting (some, not all) accented characters to standard.
To disallow lowercase and/or special characters then you should use a validator. A simple regex will identify special characters [^a-zA-Z0-9]
or special and lowercase characters [^A-Z0-9]
. The validator can also modify the input using the two methods indicated above - though you may want to make sure the user knows this is happening.
onkeypress
event or use a regex validator that fires with ajax as shown here – Luiggi Mendoza