防止超过3个字符或数字的升序或降序

防止超过3个字符或数字的升序或降序

本文介绍了正则表达式可防止超过3个字符或数字的升序或降序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正则表达式

/^(?!.*([0-9])\1{2})(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])[0-9a-zA-Z]*$/

我想对此进行修改,以防止超过3个字符或数字的升序或降序.我知道这不是最明智的解决方案,但这是必要条件,因此我不介意对所有可能的序列进行硬编码.

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.

推荐答案

我的解决方案

/^(?!.*([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]*$/

这篇关于正则表达式可防止超过3个字符或数字的升序或降序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 08:38