-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi all,
intbox,longbox,doublebox,decimalbox all are accepting %[percent symbol] and ,[comma symbol] by keyboard.
we want numeric value only. How to validate it we have constraint property in all the respective component but it is not working.
please give me some suggestion to solve the issue.
following are the code.
<longbox id="partnerTelephone" width="40%" name="partnerTelephone" value="@{partner.telephone}" maxlength="12" constraint="no negative,no zero, no empty:${c:l('common.message')} ${c:l('partner.telephone')}" readonly="${readonly}"/>
as suggestion, have a look on the attached custom constraint.
/** * Constraint for comparing the value from a <b>textbox</b>.<br> * Throws an error message if NOT empty or NOT only numbers ( 0-9 ). Used in the * PayConditions Searchbox for checking that the SearchToken is only integers or * empty</br> </br> * * <pre> * Java call:</br> * Textbox searchField = new Textbox(); * searchField.setConstraint(new OnlyEmptyAndIntegerConstraint()); * </pre> * * @author Stephan Gerth */ public class OnlyEmptyAndIntegerConstraint implements Constraint, java.io.Serializable { private static final long serialVersionUID = 4052163775381888061L; public OnlyEmptyAndIntegerConstraint() { super(); } @Override public void validate(Component comp, Object value) throws WrongValueException { if (comp instanceof Textbox) { // no need for checking ? if (((Textbox) comp).isDisabled()) { return; } // cast the value to String and trim it. final String enteredValue = ((String) value).trim(); // check if not empty if (!enteredValue.isEmpty()) { // check if not allowed signs if (!enteredValue.matches("(([0-9]+)?)+")) { throw new WrongValueException(comp, Labels.getLabel("message.error.OnlyNumbersOrEmptyAllowed")); } } } } } // Check for numbers // -------------------- // if ("-2324.00".matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) { // System.out.println("Is a number"); // } else { // System.out.println("Is not a number"); // }
Thanks For your response Mr.Stephan
That class works fine.
and please help me to validate ip address [i.e it should only contain number and period like this (192.168.1.2)]
please help me in validating ip address.
regards
Pradeep.M
Asked: 2011-03-22 07:52:45 +0800
Seen: 640 times
Last updated: Mar 23 '11