Regex to prevent ascending or descending sequence of more than 3 characters or digits

让人想犯罪 __ 提交于 2019-12-12 02:07:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!