0

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

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

Note:

  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
asked Jul 23, 2014 at 20:04

1 Answer 1

4

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.