Skip to content
Advertisement

Regex to validate that every digit is different from each other

I have to validate strings with specific conditions using a regex statement. The condition is that every digit is different from each other. So, 123 works but not 112 or 131.

So, I wrote a statement which filters a string according to the condition and prints true once a string fullfies everything, however it only seems to print “true” altough some strings do not meet the condition.

JavaScript

Advertisement

Answer

@Vinz’s answer is perfect, but if you insist on using regex, then you can use:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement