开发者

how to Validate double values with regular expression in jsf?

开发者 https://www.devze.com 2023-02-23 03:12 出处:网络
it should allow upto 30 digits before decimal and atleast 1 , atmost 2 dig开发者_如何学编程its after decimalIf you use JSF 2.0 you can use the regex-validator tag:

it should allow upto 30 digits before decimal and atleast 1 , atmost 2 dig开发者_如何学编程its 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消