On 2/10/07, "Jörn Zaefferer" <[EMAIL PROTECTED]> wrote:

I think the better approach tells the user what it expects with one
message.


Telling the user what you expect and telling the user what they did wrong
are two different things, IMO. Consider this example:

$("#myform").validate({
  rules: {
       password: { required:true, rangeLength: [5, 32],  alnum:true**},
  },
  messages {
      password: "Please enter a password that is between 5 and 32
characters long and contains only letters and numbers"
  }
});

Now, suppose the user enters this: &^%#$#@ (seven non-alphanumeric
characters)

What did they do wrong? The length is fine, so they pass the rangeLength
rule, but they fail the alphanumeric rule. What kind of error message (or
*messages*) should the user see if his input for a particular field passes
some validation rules but not all? IMO, the only thing that "Please enter a
password that is between 5 and 32 characters long and contains only letters
and numbers" tells me is that I did something wrong, but it doesn't tell me
*specifically what* (something like that is actually more appropriate as a
piece of "help text" shown alongside the password field). It doesn't tell me
that my password's length was OK but I was supposed enter only letters and
numbers. Sure the user might be able the figure this out for himself, but
why make him do more work than he's already doing?

This is much more helpful:

$("#myform").validate({
  rules: {
       password: { required:true, minLength: 5, maxLength: 32,
alnum:true*},
  },
  messages {
      password: {
          required: "Please enter a password that is between 5 and 32
characters long and contains only letters and numbers",
          minLength: "Passwords must be at least 5 characters long",
          maxLength: "Passwords must be no more than 32 characters long"
          alnum: "Passwords must contain only letters and numbers"
      }
  }
});

If the user enters nothing, he gets an error message asking him to fill in
the password field (with some helpful reminders of what to enter). If his
password is too short, his gets an error message saying it's too short. If
his password is too long, his gets an error message saying that it's too
long. If he enters non-alphanumeric characters, he gets an error message
saying that passwords must only contain letters and numbers. If his password
fails multiple rules (i.e. too short and non-alphanumeric characters), then
he could get multiple error messages explaining that his password is too
short and contains non-alphanumeric characters.

The point is that instead of just telling them that they did not enter what
you expected them to (and reiterate what you expect of them, which is what I
believe your current setup does), you tell them *specifically why* their
input was not what you expected them to enter.

** alnum is a custom rule that checks if the input contains only
alphanumeric characters (letters and numbers)

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to