Is the validity test of RegExp correct?

0

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

    $scope.verifyPasswordIsValid = function (a , b) {
    var digits_4 = new RegExp("^(\d\d)\d{0,4}$");
    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));
}
    
asked by anonymous 23.10.2015 / 14:56

1 answer

0

I noticed that the problem was in the browser's interpretation, where it removed the "\"

To solve this is simple, just add another bar on the front, that is, the code looks 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 sequential was missing the "*" in front of the dollar sign

    
26.10.2015 / 14:24