Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 75343 invoked from network); 6 Aug 2006 00:47:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Aug 2006 00:47:12 -0000 Received: (qmail 21022 invoked by uid 500); 6 Aug 2006 00:47:02 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 20541 invoked by uid 500); 6 Aug 2006 00:47:01 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 20525 invoked by uid 99); 6 Aug 2006 00:47:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Aug 2006 17:47:01 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of hrabago@gmail.com designates 64.233.182.191 as permitted sender) Received: from [64.233.182.191] (HELO nf-out-0910.google.com) (64.233.182.191) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Aug 2006 17:46:53 -0700 Received: by nf-out-0910.google.com with SMTP id o63so582402nfa for ; Sat, 05 Aug 2006 17:46:26 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=FYalCqmX78dPASQ3h+/9n0/WamiRW3HMr66kDw9gH5nQOGypDL4TIoIyxJ08yv/sAxTR6f3nRx7VpL+Iby93a6UwdVfCRuIOIeqdhxr+3VQBPIwpuJRdvN/9Dhp9pK594tErScX/gjfuUdoafJLTJIObjrRMlYse2N6hUS9b/Pw= Received: by 10.78.140.17 with SMTP id n17mr2011030hud; Sat, 05 Aug 2006 17:46:25 -0700 (PDT) Received: by 10.78.166.8 with HTTP; Sat, 5 Aug 2006 17:46:25 -0700 (PDT) Message-ID: <7b809eef0608051746o3abf43c5n74bc523a885a3554@mail.gmail.com> Date: Sat, 5 Aug 2006 19:46:25 -0500 From: "Hubert Rabago" To: "Struts Users Mailing List" Subject: Re: validate integer with a comma thousands seperator using Validator In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Try a mask validator. mask ^\$?\d+(,\d{3})*(\.\d{2})?$ Hubert On 8/4/06, fea jabi wrote: > Thanks, Eric. > > > >From: "Givler, Eric" > >Reply-To: "Struts Users Mailing List" > >To: "Struts Users Mailing List" > >Subject: RE: validate integer with a comma thousands seperator using > >Validator > >Date: Thu, 3 Aug 2006 11:45:28 -0400 > > > >You could create another validator, and inside that perform a stripping of > >non-numeric characters (stripCommas), then > >execute code similar to the existing "long range" validator like this: > > > > > > /** > > * Determines if a formatted numeric value is between a range as > >defined by > > * the user-supplied variables: min and max > > *

> > * Note: The only formattting performed is stripping off any commas. > >If the > > * resulting number does not convert to a Long, then validation will > >fail as > > * well. > > *

> > *

> > * Validation succeeds if: > > *

    > > *
  1. The value in question is null.
  2. > > *
  3. The parsed field value is within the user-supplied > >range.
  4. > > *
> > *

> > * @return > > * @param application > > * @param request > > * @param errors > > * @param field > > * @param va > > * @param bean > > */ > > public static boolean validateFormattedLongRange( > > Object bean, > > ValidatorAction va, > > Field field, > > ActionMessages errors, > > HttpServletRequest request, > > ServletContext application) > > { > > System.out.println("*** validateFormattedLongRange (" + > >field.getProperty() + ") - START"); > > boolean isValid = true; > > > > String value = null; > > value = ValidationUtils.evaluateBean(bean, field); > > if (!GenericValidator.isBlankOrNull(value)) > > { > > try > > { > > long minVal = Long.parseLong(field.getVarValue("min")); > > long maxVal = Long.parseLong(field.getVarValue("max")); > > // We don't want to do this unless we use map.put to show > >tampered value > > // value = value.replaceAll("[^-0123456789.]", ""); > > value = value.replaceAll("[,]", ""); > > long lngValue = Long.parseLong(value); > > > > if ((lngValue > maxVal) || (lngValue < minVal)) > > { > > errors.add(field.getKey(), > > Resources.getActionMessage(request, va, field)); > > isValid = false; > > } > > } > > catch (NumberFormatException nfex) > > { > > errors.add(field.getKey(), > > Resources.getActionMessage(request, va, field)); > > isValid = false; > > } > > } > > System.out.println("*** validateFormattedLongRange (" + > >field.getProperty() + ") - END, returning " + isValid); > > return isValid; > > } > > > >Define this validator in validator-rules.xml: > > > > > classname="view.struts.validator.StrutsValidationExtensions" > > method="validateFormattedLongRange" > > methodParams="java.lang.Object, > > org.apache.commons.validator.ValidatorAction, > > org.apache.commons.validator.Field, > > org.apache.struts.action.ActionMessages, > > javax.servlet.http.HttpServletRequest, > > javax.servlet.ServletContext" > > msg="errors.fmtLongRange"> > > > > > >Add a rule for a field: > > > > > > > > > > > > > > min0 > > > >max999999999 > > > > > >Define the message in the resource file (errors.fmtLongRange): > > > >errors.fmtLongRange={0} must be a valid whole number between {1} and {2}. > > > > > >-----Original Message----- > >From: fea jabi [mailto:zyxrm@hotmail.com] > >Sent: Thursday, August 03, 2006 10:01 AM > >To: user@struts.apache.org > >Subject: RE: validate integer with a comma thousands seperator using > >Validator > > > > > >can someone help me with this please? > > > > > > >From: "fea jabi" > > >Reply-To: "Struts Users Mailing List" > > >To: user@struts.apache.org > > >Subject: validate integer with a comma thousands seperator using > >Validator > > >Date: Wed, 02 Aug 2006 10:09:19 -0400 > > > > > >Using struts validator. > > > > > >have to validate the user entered value. > > > > > >The value entered should be a positive integer with a comma thousands > > >seperator. the number need not be in thousands. > > > > > >I have as below to check for positive integer without comma seperator. > >but > > >not sure how to validate if the user entered value with a comma > >seperator? > > > > > >i.e value like 25,349 // how to validate this? > > > > > > > > > > > > > > > > > > test > > > (*this* >= 0) > > > > > > > > > > > >how to validate the user entered value with a comma seperator? Thanks. > > > > > >_________________________________________________________________ > > >Don't just search. Find. Check out the new MSN Search! > > >http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > > > > > > > >--------------------------------------------------------------------- > > >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > > >For additional commands, e-mail: user-help@struts.apache.org > > > > > > >_________________________________________________________________ > >Don't just search. Find. Check out the new MSN Search! > >http://search.msn.click-url.com/go/onm00200636ave/direct/01/ > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > >For additional commands, e-mail: user-help@struts.apache.org > > > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > >For additional commands, e-mail: user-help@struts.apache.org > > > > _________________________________________________________________ > Express yourself instantly with MSN Messenger! Download today - it's FREE! > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org