5

I have a simple form for the user to sign up to my site; with email, username and password fields. We are now trying to implement an ajax validation so the user doesn't have to post the form to find out if the username is already taken. I can do this either on keyup event or on text blur event. My question is, which of these is really the best way to do?

Keyup

From the user POV, it would be good if the validation is done as and when they are typing, (on key up event) - of course, I am waiting for half a second to see if the user stops typing before firing off the request, and user can make any adjustments immediately.

But this means I am sending way more requests than if I validated the username on Blur event.

Blur

The number of requests will be much lower when the validation is done on blur event, But this means the user has to actually go away from the textbox, look at the validation result, and if necessary go back to it to make any changes and repeat the whole process until he gets it right.


I had a quick look at google, tumblr, twitter and no one actually does username validations on keyup events, (heck, tubmlr waits for the form to be posted) but I can swear I have seen keyup validations in a lot of places too.

So, coming back to the question, will keyup validations be too many for server, is it an unnecessary overhead? or is it worth taking these hits to give user a better experience?

ps: all my regex validations etc are already done on javascript and only when it passes all these other criteria does it send a request to server to check if a username already exists. (And the server is doing a select count(1) from user where username = '' - nothing substantial, but still enough to occupy some resource)

pps: I'm on asp.net, MS SQL stack., if that matters.

2
  • For the user experience part of your question, you should ask on User Experience Stack Exchange. The technical part of it it's on topic here, but if you decide to also ask on User Experience, please revise this version of the question to be focused only on the technical part.
    – yannis
    Commented Apr 13, 2012 at 11:06
  • @YannisRizos, I was confused where to post this, as the problem has two parts to it and the solution has to consider both parts.. finally ended up posting here because I, as a developer, am more concerned about the technical part.
    – iamserious
    Commented Apr 13, 2012 at 12:27

5 Answers 5

8

From user point of view, I would want to know whether whatever I am doing at given moment is going to fail as soon as possible. Which is why I suggest going for key-up validation. Few reasons for it:

  • gives user nice real-time interaction and security feel (system is watching whether you do what you're supposed to correctly)
  • helps user to focus at one task at time (selecting name in this case)

Problem with blur validation (or any other lost focus ones) is that at the point you're doing validation, user is probably interested in something else. I would expect that once I fill the name field, I simply move on with form and don't bother with name anymore until I decide to validate it (or submit). Situation where I'm done with user name and say, started thinking where I've put my birth certificate so I can check what phase was moon in at the time I was born, and then suddenly system tells me I need to go back to check username again is highly unwanted.

Keep in mind this might be enough for some users to leave your website and never come back at this point. And I'm not exaggerating here, many times I've seen people (myself included), who would leave app or website/chose different one purely for the most ridiculous reasons like "this button does not do what I though it would" or "why can't I drag this tab?". Remember that you want to not only attract user, but even more importantly - keep him and make him come back. And frustration with very first interaction he'll have with your service is not going to help achieving that :-)

So - let users decide what they want to focus on at time. Either go with real-time validation as user types, or grand-total validation upon form submit.

On top of that, you need to think how those select count(1) ... queries will impact your server. If it is ready to process thousands of other queries at time, extra 3 to check user name won't differ too much. Not to mention, user account creation is process which doesn't happen often (usually only once per user). Don't optimize prematurely, see whether those queries will be an issue at all.

5
  • 1
    I'd just add: I like validation on keyup in this situation as long as there's 500-1000ms wait, and to avoid annoying slow typists don't make the validation too obtrusive. E.g. don't change the field background or even border; just add a message to one side of it. Commented Apr 13, 2012 at 12:44
  • What's wrong with changing the background/border, if people don't realise and then wonder why they can't submit, a red background/border for example is a wonderful visual cue
    – Paul C
    Commented Apr 13, 2012 at 13:09
  • Real-world websites can't afford to do validation only as the user types, and not at form submit time. Not everybody has JavaScript enabled, and (more importantly) you cannot assume that the JavaScript was actually run (comment spam robots, for example, won't run it). Commented Apr 13, 2012 at 13:23
  • 1
    @JamesYoungman And if you only validate in the browser, you are quite vulnerable to the telnet (or wget) web clients. In-browser validation is good for stopping the "submit, wait, correct, submit..." loop though.
    – Vatine
    Commented Apr 13, 2012 at 13:37
  • 1
    Thanks for the answer, was very helpful, esp the last paragraph, don't optimize prematurely!
    – iamserious
    Commented Apr 13, 2012 at 14:36
2

create a 1 second timeout on keyup and cancel the previous one

<input onkeyup="cleartimout(lastTimeout);lastTimeout=setTimeout(validate,1000);">

this way fast typers don't trigger a validate on each keyup but when the user stops typing the username is validated and gets feedback on whether it is free

5
  • 1
    Or use documentcloud.github.com/underscore/#debounce
    – jd01
    Commented Apr 13, 2012 at 10:20
  • Hi, I'm already doing this, on 700ms... but even so, there will be a lot more requests compared to blur right?
    – iamserious
    Commented Apr 13, 2012 at 10:31
  • Why not test and benchmark it?
    – ridecar2
    Commented Apr 13, 2012 at 10:40
  • @jd01, that's interesting, but I can do the same thing with just a settimeout and canceltimeout
    – iamserious
    Commented Apr 13, 2012 at 10:50
  • @ridecar2, hi, I googled load testing and found a bunch of stuff. will look at it, thanks
    – iamserious
    Commented Apr 13, 2012 at 10:59
1

When using keyup are you going to the server after every keystroke? Is there a minimum limit on the length of the username? Are there any other conditions the name needs to satisfy. If so you can check for these on the client side first, before going back to the server and finding if the name is valid. If this is the approach you are taking already then you won't be doing too many calls to the server, therefore using keyup seems to be best and most responsive.

As you say using blur means your user has left the textbox and perhaps their focus is elsewhere.

5
  • Hi @Daniel, Yes, I do have minimum length for username, as well as other general rules like no spaces etc.. and all this is being taken care of in js, only when these things are all okay, I am sending a request to server.. Thanks for the answer though.
    – iamserious
    Commented Apr 13, 2012 at 12:25
  • So you won't be hitting the server that often, and the JS validation will take care of details such as 'you need to have a username of six characters or more'. Commented Apr 13, 2012 at 13:38
  • 1
    @iamserious - I hope you are checking those same conditions sever side too. Either that or not letting the user on your page if they don't have JavaScript enabled. Otherwise you are going to get in trouble.
    – Tyanna
    Commented Apr 13, 2012 at 14:15
  • @Tyanna very good point. Never forget that javascript can be disabled, and it's always better to validate on the server-side as well. Better to be safe than sorry. Commented Apr 13, 2012 at 14:19
  • @Tyanna, Ha, yes, I am checking them on server side too, but on post submit, and not on keyup.
    – iamserious
    Commented Apr 13, 2012 at 14:35
1

I'd prefer not to have to create another user name and password. OAuth/OpenId is the way to go. That being said nothing is more annoying than submitting a form only to get a "username already taken" error. I can't remember seeing a signup form that validates on keyup. Lost focus is acceptable to me. And as you mentioned less chatty from a technical perspective.

0

Have a required user name length and when it gets close, start getting ready to notify the user whether or not it is unique.

Sometimes it is better to let them know what is available than what has been taken. There has to be a security concern if someone can just send keys to this field and capture all of your user names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.