开发者

how to Validate double values with regular expression in jsf?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜