Skip to Content
author's profile photo Former Member
Former Member

how to define a validation constraint, After decimal (.) it should accept (*.##) two digits only

Hi Experts,

How can i define a validation constraint, After decimal (.) it should accept (*.##) two digits only.

Regards,

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 26, 2016 at 09:19 PM

    Hi, Amit, Yashwanth,

    One simple way to check is using regex. For example:

             final String demicalNumber = numberEntry.demicalField;
             if (!demicalNumbervalue.matches("\\d*\\.\\d\\d"))
             {
                 throw new InterceptorException("Decimal number only accept 2 two digits only");
             }
    
    

    If the attribute is defined other than String, toString() can be used to convert to String first.

    If the validate is used before save to database, Validate Interceptor can be used. For more detail of Validate Interceptor, please refer to: https://help.hybris.com/6.0.0/hcd/8bfbf43e8669101480d0f060d79b1baa.html

    Regards

    Haitao

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 20, 2016 at 07:31 AM
    -1

    Hi Amit

    Did you find solution for this. I have similar requirement.

    Regards, Yashwanth

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.