1
votes

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

2
Do you want to only allow uppercase letters or do you want to convert all letters to uppercase?KidTempo
Looks like you must apply a JavaScript function on your onkeypress event or use a regex validator that fires with ajax as shown hereLuiggi Mendoza
KidTempo, I wanna to convert all letters to uppercase, just permit uppercase and words with no special characters.Ronaldo Lanhellas
You're not clear in your concrete functional requirement. In your previous comment you basically said that you want to convert lowercase to uppercase, but then you basically say that you want to validate ("permit") that the input is all uppercase. That are two completely different things. What exactly do you want? E.g. when the enduser enters "föó", what do you want JSF do to? Validate and show error so that enduser has to fix itselves? Or convert silently to "FOO" and proceed using converted value without showing error?BalusC

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.