I need to increase the validate-password class length to 8 characters.

How can I add that script in that validate-password class?


  1. I don't want to create a new validation class
  2. I don't want to add any class name (validate-length) to the password field

1 Answer 1


Here's a way that should work and no need to modify a core JS file. Just drop it into a custom JS file and ensure it's included after validation.js.

Validation.add('validate-password', 'Please enter 8 or more characters. Leading or trailing spaces will be ignored.', function(v) {
    var pass=v.strip(); /*strip leading and trailing spaces*/
    return !(pass.length>0 && pass.length < 8);

It essentially just replaces the callback validation method that is originally set in validation.js with one that checks for 8 characters or more.

I'd be curious to know why you don't want to add the validate-length field as it seems like an easier approach to me.

NOTE: I haven't used this personally I just whipped it up on the demo store and tested it briefly.

  • I'm curious why the return !() when return pass.length>0 && pass.length >= 8 will work and (to me) is more legible?
    – philwinkle
    Jul 24, 2014 at 0:32
  • @philwinkle I agree. I just copy/pasted what was in validation.js to keep it consistent.
    – beeplogic
    Jul 24, 2014 at 0:56

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.