Hi, I have the following Java code to validate a password box.
Basically it checks that the password can't be null, is between 8-15
characters, and must contain both numbers and letters.

public static boolean validatePassword(PasswordTextBox box, Label
errorLabel) {
                String text = box.getText();
                if(text.isEmpty()) {
                        ValidatorUtil.onFailure(box, 
custom.passwordMayNotBeNull(),
errorLabel);
                        return false;
                } if(text.length() < 8 || text.length() > 15) {
                        ValidatorUtil.onFailure(box, 
custom.passwordHasInvalidLength(8, 15,
text.length()), errorLabel);
                        return false;
                } if(!text.matches(CustomMessages.REGEX_PASSWORD)) {
                        ValidatorUtil.onFailure(box, 
custom.passwordHasInvalidFormat(),
errorLabel);
                        return false;
                }
                return true;
        }

This works fine in Firefox, but it does not work in IE.  The
JavaScript compiles down to this for IE8:

function validatePassword(box, errorLabel){
  var text, matchObj;
  text = $getPropertyString(box.element, 'value');
  if (!text.length) {
    setStyleName(box.element, 'validationFailedBorder', true);
    ($clinit_114() , errorLabel.element).innerText = 'You must provide
a password.';
    return false;
  }
  if (text.length < 8 || text.length > 15) {
    onFailure_1(box, 'Sorry, your password must be between 8 and 15
characters long (you have ' + text.length + ' characters).',
errorLabel);
    return false;
  }
  if (!(matchObj = (new RegExp('^(?=.*\\d)(?=.*[a-z]).{8,15}$')).exec
(text) , matchObj == null?false:text == matchObj[0])) {
    setStyleName(box.element, 'validationFailedBorder', true);
    ($clinit_114() , errorLabel.element).innerText = 'Sorry, your
password must contain both letters [a-z] and numbers [0-9].';
    return false;
  }
  return true;
}

The behavior is a bit odd.  It passes the text.length checks, but then
fails the regex expression (which also has length checks with {8,15}.
It always prints: 'Sorry, your password must contain both letters [a-
z] and numbers [0-9].' in IE, but in Firefox, it works fine...for
inputs like this:

abcd1234 <- valid password, 8 characters with letters and numbers

Even more strange is the fact that if I enter a password with 12
characters with both letters and numbers, IE passes, like this:

abcd1234abcd

But if I enter only 11 characters, it fails:

abcd1234abc

Any clues on what is wrong here?

Regards,
Davis




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to