问题
I have a regex
/^(?!.*([0-9])\1{2})(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[0-9a-zA-Z]*$/
I would like to modify this to to prevent ascending or descending sequence of more than 3 characters or digits. I know this is not the most sensible solution but this is the requirement so I don't mind hard coding all the possible sequence.
回答1:
My solution
/^(?!.*([0-9])\1{2})(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?!.*0123|.*1234|.*2345|.*3456|.*4567|.*5678|.*6789|.*3210|.*4321|.*5432|.*6543|.*7654|.*8765|.*9876|.*1122|.*2233|.*3344|.*4455|.*5566|.*6677|.*7788|.*8899|.*9900|.*0011|.*1100|.*(?i)qwerty|.*(?i)abcd|.*(?i)bcde|.*(?i)cdef|.*(?i)defg|.*(?i)efgh|.*(?i)fghi|.*(?i)ghij|.*(?i)hijk|.*(?i)ijkl|.*(?i)jklm|.*(?i)klmn|.*(?i)lmno|.*(?i)mnop|.*(?i)nopq|.*(?i)opqr|.*(?i)pqrs|.*(?i)qrst|.*(?i)rstu|.*(?i)stuv|.*(?i)tuvw|.*(?i)uvwx|.*(?i)vwxy|.*(?i)wxyz|.*(?i)zyxw|.*(?i)yxwv|.*(?i)xwvu|.*(?i)wvut|.*(?i)vuts|.*(?i)utsr|.*(?i)tsrq|.*(?i)srqp|.*(?i)rqpo|.*(?i)qpon|.*(?i)ponm|.*(?i)onml|.*(?i)nmlk|.*(?i)mlkj|.*(?i)lkji|.*(?i)kjih|.*(?i)jihg|.*(?i)ihgf|.*(?i)hgfe|.*(?i)gfed|.*(?i)fedc|.*(?i)edcb|.*(?i)dcba)[0-9a-zA-Z]*$/
来源:https://stackoverflow.com/questions/36691092/regex-to-prevent-ascending-or-descending-sequence-of-more-than-3-characters-or-d