0

I'm trying to validate a password and if it is ok, it will keep in an array regular expression only once. When I run the script in the mozilla browser, I get the following error: 'seguridadPass [i]. Test is not a function'. I would also like to know how I can do to delete the array 'comprobaciones', those regex that have not been used. Thank you for your help.

CODE

JAVSCRIPT

var compMay = /[A-ZÑ]/;
var compMin = /[a-zñ]/;
var compNum = /(?=.*\d)/;
var compCarEsp = /[!@#$%^&*(){}[\]<>¿¡?/|.:;_-]/;
var seguridadPass = []; 
seguridadPass.push(compMin,compMay,compNum,compCarEsp);
comprobaciones = [];

$('#write').keyup(function(){

var pass = $(this).val();
if(pass!=''){
    for(i=0;i<seguridadPass.length;i++){
        if(seguridadPass[i].test(pass)){
            //alert(seguridadPass[i]);
            for(j=0;j<comprobaciones.length;j++){
                if(comprobaciones[j]!=seguridadPass[i]){
                    comprobaciones.push(seguridadPass[i]);
                }
            }
        }
    }
}
else{
    comprobaciones.splice(0,comprobaciones.length);
    //comprobaciones = [];
}
});

2 Answers 2

3
seguridadPass.push(compMin,compMay,compNum,compCarEsp,8);

8 is not a regexp.

Sign up to request clarification or add additional context in comments.

Comments

0

Your array mostly contains RegExp objects, but you've also pushed the number 8 to your array here:

seguridadPass.push(compMin,compMay,compNum,compCarEsp,8);

The Number type in JavaScript does not have a test method*. Remove the 8 and it should work:

seguridadPass.push(compMin,compMay,compNum,compCarEsp);

* Unless you provide one in Number.prototype.

4 Comments

Yes, I made a stupid mistake introducing 8. How can I check and delete elements in the array comprobaciones (regex) not in use?
@j_arab What do you mean by 'not in use'?
for example, if I decide to delete a character in the input, if it has been used a regex less than those stored in the array 'checks', delete that regex, if it has been stored previously
@j_arab If I understand what you want, it seems like the easiest solution would be to clear the entire array, re-run this entire script again.

Your Answer

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.