Is the Regexp validity test correct?

Asked

Viewed 58 times

0

I am trying to validate a password through Regexp, in javascript, but it only returns false when it should actually return true, for having given match value, someone would know if there is something wrong with my code?

    $scope.verifyPasswordIsValid = function (a , b) {
    var digits_4 = new RegExp("^(\d\d)\d{0,4}\1$");
    var seq_number = new RegExp("^1*2*3*4*3*2*1$");
    var seq_alphab = new RegExp("^a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*$");

    console.log("reg alp: "+seq_alphab.test(a));
    console.log("reg 4: "+digits_4.test(a));
    console.log("reg number: "+seq_number.test(a));
}
  • Related http://answall.com/questions/42459/express%C3%A3o-regular-n%C3%A3o-works-correctly-in-webform/42486#42486

  • Examples of passwords you are testing must be correct and incorrect.

  • for digits-4 to using "1111", for seq_number to using "1234", for seq_alphab to using "abcd", i.e.

1 answer

0


I realized that the problem was in the interpretation of the browser, where he removed the bars "\" inserir a descrição da imagem aqui

to solve this is simple, just add another bar in front, IE, the code is like this:

   $scope.verifyPasswordIsValid = function (a , b) {
var digits_4 = new RegExp("^(\\d\\d)\\d{0,4}\\1$");
var seq_number = new RegExp("^1*2*3*4*3*2*1*$");
var seq_alphab = new RegExp("^a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*$");

console.log("reg alp: "+seq_alphab.test(a));
console.log("reg 4: "+digits_4.test(a));
console.log("reg number: "+seq_number.test(a));

}

for the sequences was missing the "*" in front of the dollar sign

Browser other questions tagged

You are not signed in. Login or sign up in order to post.