logo

NJP

Alphanumeric RegEx || Prevent two consecutive characters

Import · Apr 15, 2021 · article

This is something adding for people I've seen struggling to get the exact RegEx to refer specially in case of Alphanumeric String Validation that's not accepting two consecutive characters/numbers.

Even I've added one to get refer in case of Special Characters and can make it work accordingly.

RegEx Pattern : /([a-zA-Z0-9])\1(?=[a-zA-Z0-9]){0,}/g

Can add with Special Characters too : /([a-zA-Z0-9@!#$%&*])\1(?=[a-zA-Z0-9]){0,}/g

Hope this will help some of you guys in some ways to make things easy. Thanks

View original source

https://www.servicenow.com/community/itsm-articles/alphanumeric-regex-prevent-two-consecutive-characters/ta-p/2315264