How do I add a method to a PASSWORD CLASS That checks for Validity

20 Views Asked by At

In Javascript, how to add method to a password class that checks for validity.

how to add method to a password class that checks for validity in javascript.

1

There are 1 best solutions below

0
Anubhav Sharma On

I am not completely sure about the requirement, but perhaps below would help

class Password{    
    constructor(passString){
        this.passString = passString;
    }

    checkLength = () => { 
        return this.passString.lenght>8;
    }

    checkSpecialChars = () => { // TODO Need to implement
        return true;
    }

    checkUpperChar = () => { // TODO Need to implement
        return true;
    }

    checkLowerChar = () => { // TODO Need to implement
        return true;
    }

    isValid = () => {
        return this.checkLength() && this.checkSpecialChars() && this.checkLowerChar() && this.checkUpperChar();
    }
}

let pass = new Password("ANUBHAV");
console.log(pass.isValid());