I generally write format functions to pass back the empty string if what
is passed in is not valid.  Of course, I think of them less as string
formatting than data normalizaion.  :-)

Assuming you're doing validation and normalization elsewhere, and now
you just want to make it look pretty, then it's pretty much (IMHO) a
stylistic decision, and whether to do it your way or use the established
standard is a question I can't answer.

But I will anyway.  For phone numbers, I'd want it to return
"(   )    -    " if the empty string was passed in.  But that's just me.
  :-)

--Ben

Deanna Schneider wrote:

> Hey all,
> So, in concert with another group of developers (that work on the same
> server), we put together a "format.cfc" that just handles a lot of the
> basic format things we do - things like outputting a phone number in a
> specified format, capitalizing this thing we use called a netid -
> stuff like that.
>
> It turns out that the other developer thinks that you should never use
> a format function to do any validation. In other words, if you pass an
> empty string to a phone() function, it should return "()-" instead of
> returning an empty string. All the functions that insert stuff are set
> up that way.
>
> So, I'm thinking about that. And, I was darn sure that 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.
>
> 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?
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to