regex - Javascript Validate number, nonrepeating, nonsquential -
i trying validate input.
the input must numeric, 9-digits long.
we need prevent 000000000, 111111111, 222222222, 123456789, 234567890, 098765432, 987654321, 010101010, 121212121, 000000001, 000000010 , on type inputs.
the thing can think of testing each possibility. monstrous amount of code, or regex like:
var input="111111111"; var regex = /000000000|11111111|222222222|123456789|234567890|098765432|987654321|010101010|121212121|00000001|000000010/; // , on , on , on....... var found = input.match(regex); console.log(found);
does have better way this?
you can avoid repeated sequences , numbers 111811111 with:
\b(?!(?:(?=(\d))((\d+)\3)\2*\1|(\d{3})\4{2}|(?=\d*(\d)(?!\5)(\d))(?:\5*\6\5*|\6*\5\6*))\b)\d{9}\b
you can test: 123456789, 012345678, 876543210 etc.
with:
if ( parseint(s) + parseint(s.split("").reverse().join("")) % 111111111 == 0 )
Comments
Post a Comment