views:

51

answers:

2

By "cleaned" I mean formatting inputs such as "a1b2c3" into "A1B 2C3" or "5551234567" into "(555) 123-4567". I figure we have few options:

  1. As the user is typing. For instance, when a user is typing a postal code, all letters are instantly capitalized, or after the user types 3 digits of a phone number, it puts brackets around them.
  2. When the field loses focus.
  3. Never. Formatting happens on the server-side only, just before it is inserted into the DB. The user never gets to see how it was formatted unless it is displayed on the site somewhere.
    (3b) If there were form errors, or on the confirmation page. If there are form errors and the form needs to be re-displayed, the formatting on the valid inputs will appear, or if you have a confirmation page (are these inputs correct?) they will show there.
  4. Never ever. Data should be dumped into the database as-is and only formatted in the template/view just before it is displayed back to the user.

What do you think? I think I like (2). Reminds me of how code-formatting works in Visual Studio (happens when you close a brace or type a semi-colon).

+1  A: 

I'd go with either (1) or (2), depending on the kind of input. (1) is probably most user-friendly if done right, but it will be more complex to implement neatly (e.g., what happens if I delete a digit from a hyphenated phone number - or a hyphen?). Go with (1) if you can afford it, otherwise (2).

Gintautas Miliauskas
Yeah...that's the other issue with (1). I don't like it because it's tricky to implement, and from a user-perspective, perhaps a bit confusing. I don't like when sites mess with my input before I'm even done typing it.
Mark
For what it's worth, reformatting when the field loses focus may also be confusing. The user may spend time reformatting the string manually, unaware that the software is ready to do that for him. I personally prefer on-the-fly formatting, as long as it is reliable and foolproof.
Gintautas Miliauskas
Good point, but he'll probably learn quickly after he enters one input. It's a member-site anyway, we expect repeat customers. They'll get used to my forms, whether they like it or not ;)
Mark
+1  A: 

I follow the same method I use for validation. Once on the client side, once on the server side. Whether it happens on loose focus or as they type it doesn't really matter.

Biff MaGriff
So you vote on (1) or (2).
Mark
I don't think consistency matters in that respect as long as it happens. (1) and (2) on different controls in the same form would be fine. I mean, how are you going to fix as you type for a user entering a date in a DD-MMM-YYYY format?
Biff MaGriff
But yeah, don't forget to format again on DB insert, update, etc, you don't want some ass sending raw http posts with junk data to mess up your database.
Biff MaGriff
@Biff: Or simply disabling JS :) I'd format it twice.
Mark