I need to increase the validate-password class length to 8 characters.
How can I add that script in that validate-password class?
Note:
- I don't want to create a new validation class
- 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
!()whenreturn pass.length>0 && pass.length >= 8will work and (to me) is more legible?philwinkle– philwinkle2014年07月24日 00:32:35 +00:00Commented Jul 24, 2014 at 0:32 -
@philwinkle I agree. I just copy/pasted what was in
validation.jsto keep it consistent.beeplogic– beeplogic2014年07月24日 00:56:03 +00:00Commented Jul 24, 2014 at 0:56
Explore related questions
See similar questions with these tags.