> they shouldn't.
> Then, I tried a few of the built in functions
> (dollarformat(),
> decimalformat(), numberformat()) and it turns out that
> they all give
> you back zero, formatted, if you pass in an empty string.
Personally I'd rather the dollar, decimal and numberformat functions
return an empty string rather than zero in response to a non-numeric
value, but that's neither here nor there...
> So, what do you think? Should you have to write:
> <cfif len(myphone)>
> #phone(myphone)#
> </cfif>
> Or, should you just be able to call #phone(myphone)# and
> have it
> return an empty string if it's passed an empty string.
> What's your
> best practice?
My opinion, format functions should be as "intuitive for display" as
possible, unless they're not being used for display (i.e. ensuring a
given format prior to insert into a db)... They should be "fire and
forget" for displaying to the end-user, so no, I don't think you
should have to check the length before applying the phoneformat()
function -- mostly because I think doing that just results in reams
and reams and reams of unnecessary code eventually... If you need 2
separate functions (one for display and one for other things) then so
be it, but there should always be a highest-level display function
that handles every condition for you when you're just displaying to an
end user... and of course, you can always use optional extra arguments
to tell the function what it should do with values that don't match
the pattern it needs, i.e. phone(myphone,"") tells it to return an
empty string if it's not a valid phone number... phone(myphone,"not
given") tells it to return the string "not given" instead. I'd default
to the empty string for most format functions.
s. isaac dealey 954.927.5117
new epoch : isn't it time for a change?
add features without fixtures with
the onTap open source framework
http://www.sys-con.com/story/?storyid=44477&DE=1
http://www.sys-con.com/story/?storyid=45569&DE=1
http://www.fusiontap.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
