Question about Range validation

4 views
Skip to first unread message

Marc Esher

unread,
Nov 10, 2011, 7:46:52 AM11/10/11
to validate...@googlegroups.com
Hey Bob,

Was "Range" validation intended for non-numbers as well as numbers?

Here's why I ask:

I have a latitude property with a range rule between -90 and 90.

I learned yesterday that this value will pass this validation: "43 28.3"

Notice the space?

Now, try this in a scribble pad:

LT 180? #"43 28.3" LT 180#
<br>
LT 90? #"43 28.3" LT 90#
<br>

So what was happening on my form was that for latitude, that number
with a space was passed through as valid, and the same value for
longitude was being flagged as invalid.

yet "a" and "b" and "mcdonalds" all fail the range test (expectedly).

So I figured that the range validation was *intended* to be used only
for numeric validation, but thanks to CF's, uh, quirks, there are
cases where non-numbers can in fact fall within the ranges.

In my copy of VT, I modified the Range validator to do an isnumeric
check and fail if that doesn't pass

<cfif shouldTest(arguments.validation) AND
( NOT isNumeric(theValue) OR (theValue LT parameters.Min OR
theValue GT parameters.Max) )>

Should this be added to the VT?

Marc

P.S. If you want more ColdFusion fun, try this:

#lsIsDate('4/15/201717')#
<br>
#isDate('4/15/201717')#
<br>
#lsIsDate('4/15/20171')#
<br>
#isDate('4/15/20171')#
<br>
#isValid('date', "3.1458")# and #isDate('3.1458')# and #lsIsDate('3.1458')#

Jamie Krug

unread,
Nov 10, 2011, 9:39:43 AM11/10/11
to validate...@googlegroups.com
My 2 cents: this should be added to VT. Since it seems "Range" is really intended for numeric only, Marc's fix makes perfect sense to me. If you really wanted more flexibility down the road, you'd have to maybe rename "Range" to "NumericRange" or something like that. Either that, or the rule would require an additional parameter to specify the type of range. If you get fancy like that, you might even "sniff" the rule parameter(s) before applying the isNumeric() check, like so:

<cfif shouldTest( arguments.validation ) AND
    ( 
        ( isNumeric( parameters.Min ) AND
            NOT isNumeric( theValue )
        )
        OR
        ( theValue LT parameters.Min OR
            theValue GT parameters.Max
        )
    )
>

Cheers,
Jamie


--
You received this message because you are subscribed to the Google Groups "ValidateThis-dev" group.
To post to this group, send email to validate...@googlegroups.com.
To unsubscribe from this group, send email to validatethis-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis-dev?hl=en.


Marc Esher

unread,
Nov 10, 2011, 9:49:17 AM11/10/11
to validate...@googlegroups.com
On Thu, Nov 10, 2011 at 9:39 AM, Jamie Krug <ja...@thekrugs.com> wrote:
> My 2 cents: this should be added to VT. Since it seems "Range" is really
> intended for numeric only, Marc's fix makes perfect sense to me. If you
> really wanted more flexibility down the road, you'd have to maybe rename
> "Range" to "NumericRange" or something like that.

I've been preferring to just write custom range validators when
necessary. So, "SRV_DateRange", for example.

I believe a validator should do one thing and do it well.

Jamie Krug

unread,
Nov 10, 2011, 9:57:19 AM11/10/11
to validate...@googlegroups.com
On Thu, Nov 10, 2011 at 9:49 AM, Marc Esher <marc....@gmail.com> wrote:

I've been preferring to just write custom range validators when
necessary. So, "SRV_DateRange", for example.

I believe a validator should do one thing and do it well.

Yeah, I dig that; and that's probably how lots of folks have been using "Range" already (as a numeric range). So, ignore my over-thinking there ;-) +1 for adding Marc's `NOT isNumeric()` fix to VT :)

Bob Silverberg

unread,
Nov 10, 2011, 10:47:04 AM11/10/11
to validate...@googlegroups.com
Yeah, Range was always intended as numeric range. Please submit a
pull request for the fix, Marc, and thanks!

> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis-dev" group.
> To post to this group, send email to validate...@googlegroups.com.
> To unsubscribe from this group, send email to
> validatethis-d...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/validatethis-dev?hl=en.
>

--
Bob Silverberg
www.silverwareconsulting.com

Marc Esher

unread,
Nov 10, 2011, 3:53:18 PM11/10/11
to validate...@googlegroups.com
will do, Bob
Reply all
Reply to author
Forward
0 new messages