Currently i have a field that takes in a telephone number.
It performs a length validation without fail. What i really want is there to be length validation only when a value is input, and no validation when there is no value. How can i accomplish this?
<p:inputText id="corporateTel" label="#{labelResource.telephone}">
<f:validateLength minimum="5" maximum="20" />
</p:inputText>
This is already the default behaviour. Your problem is caused elsewhere. Perhaps you used an
intinstead ofIntegerorString, so that it defaults to0instead ofnull. Or perhaps you used anIntegerwhile running the webapp on Tomcat/JBoss wherein the default Apache EL implementation would implicitly coerce it to0instead ofnull. You can turn it off by adding the following VM argument:Or use
Stringinstead ofInteger. This is also a more appropriate data type for phone numbers as they may have a leading0which would otherwise be chopped off when usingInteger.