Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Password validation with sequential numbers

I need to check if has a 2 numbers sequence, if has comes back true, if not false.

example:

113489 //false on 11
123456 // true
189033 // false on 33

Can be with regex or without regex.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I don’t know how to do it with regex, so why not just loop over it

var str = "189033";

function check(str) {

  var arr = str.split("");
  var last = null;
  for (var i = 0; i < arr.length; i++) {
    var digit = arr[i]
    if (digit == last) {
      return false;
    }
    last = digit;
  }
  return true;
}
console.log(check(str))
console.log(check("123456"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading