how to restrict only letters and numbers at p:inputMask - jsf

I want to restrict my <p:inputMask> with only letters and numbers without giving any size (max-legth) limit. I tried to use mask attribute but when I use mask attriibute it gives a max-length for my inputMask. Could you please help me to solve this issue ?
Sample Code :
<p:inputMask value="#{gercekKrediBasvuruDetayGirisView.kisi.ticariHarfSeri}"
required="true" mask="***"
requiredMessage="#{msg['GercekKrediBasvuruTuketiciMaliBilgiler.belgeSeriNull']}"
/>

If your input does not have to be <p:inputMask> and can be <h:inputText> or <p:inputText> then the easiest way to go would be to use it with regex:
<h:inputText id="inputField" value="#{backingbean.username}" validatorMessage="Value does not match pattern.">
<f:validateRegex pattern="^[a-zA-Z0-9]+$" />
</h:inputText>
<h:message for="inputField" />
If you only allow lower case letters go with ^[a-z0-9]+$.
<p:inputMask> is designed for somewhat stricter validation than only letters and numbers.

Related

JSF <h:inputText> should accept just number

i 've been looking a lot about how to make my allows just number to be inserted inside , seems quite easy but it doesn't work in anyway.
I have this code :
<p:fragment id="thresoldPrice">
<h:inputText type="number"value="" disabled="#{!tradingFunnelCBean.tradingFunnelMBean.conditionalOrder}" styleClass="#{!tradingFunnelCBean.tradingFunnelMBean.conditionalOrder ? '' : 'num-col'} middle-space">
<f:convertNumber pattern="#.####" integerOnly="true" maxFractionsDigit="4"/>
<p:watermark for="thresoldPrice"value="#{localizationBean.getMessageValue('EP3.GIMB.TRADINGFUNNEL.PRIVATE.LABEL.WATERMARK', languagePreferenceBean.selectedPreference)}" />
</h:inputText>
</p:fragment>
but it keeps accepting String values. i would also like to make the value inserted in this format "#.####" but the pattern attribute of the h:inputText doesn't make anything.
Any suggestion?

f:convertNumber silently converts invalid numbers like 1a to 1 without showing conversion error message

I try to check if an input text is a Integer or not. I have wrote this piece of code:
<h:inputText id="amount" value="#{receipt.amount}" required="true" converterMessage="error" requiredMessage="error" validatorMessage="error" >
<f:validateLongRange minimum="1" maximum="#{receipt.all}" />
<f:convertNumber IntegerOnly="true" />
</h:inputText>
and it is working but in one case if I put for example "1a" it converts me this to "1". How can I check this in JSF? I would like to see a message if input is incorrect. I have made validation in my bean and everything worked but I have to do in JSF. Could anybody explain how to set maximum="#{receipt.all} correct? If I put in this way I have a zero. I try to refres this input but it didn't work.

Double JSF only without comma or dot

how is it possible to display a double like "1"
At the moment the double appears with 1.0
But I want to have for example 1,5, too.
But if I have only 1 (the numbers after the comma or dot is zero, than I want to have a value without comma or dot)
How can I do this?
Thanks
I suppose this is what you want to achieve:
<h:outputText value="1,0">
<f:convertNumber minFractionDigits="0" />
</h:outputText>
Will output 1
<h:outputText value="1,5">
<f:convertNumber minFractionDigits="0" />
</h:outputText>
Will output 1,5
Make sure to use correct decimal separator depending on your Locale when testing this.
You can play arround a bit more with the f:convertNumber tag. http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_convertNumber.html

Validation problem for ensuring that entered value contains alphabet only

How can i make sure at conversion and validation phase during the JSF lifecycle that entered value in <h:inputText> contains alphabets only?
Thanks in advance.
You can use <f:validateRegex> for this.
<h:inputText id="input" value="#{bean.input}" validatorMessage="Please enter alphabets only">
<f:validateRegex pattern="[a-zA-Z]*" />
</h:inputText>
It accepts the same regex syntax as the Pattern class. Check its documentation. You can also use \p{Alpha} instead.
<f:validateRegex pattern="\\p{Alpha}*" />
Or if you're using bean validation (as confirmed by your question history), then you can also use #Pattern for this.
#Pattern(regexp="\\p{Alpha}*", message="Please enter alphabets only")
private String input;

how to Validate double values with regular expression in jsf?

it should allow upto 30 digits before decimal and atleast 1 , atmost 2 digits after decimal
If you use JSF 2.0 you can use the regex-validator tag:
<h:inputSecret id="password" value="#{user.password}">
<f:validateRegex pattern="add your pattern here" />
</h:inputSecret>
If you are still on JSF 1.x I think you have to write your own custom validator by creating a class that implements javax.faces.validator.Validator interface. Here is a good tutorial how to achieve this.
Here in this example is the solution i suggest for validating double:
<h:inputText id="someField" value="#{yourBean.doubleValue}">
<f:convertNumber minFractionDigits="2" />
<f:validateDoubleRange minimum="1" maximum="30"/>
</h:inputText>
Use the attributes of the convertNumber tag to set the limits you need.

Resources