I need to prevent entering 5
digit sequential numbers like 12345
, 45678
etc. in a text box.
I had tried with the following regular expression, but it is not working
var regex = /^\(?[0-9]{3}(\-|\)) ?[0-9]{3}-[0-9]{4}$/;
It is better to use non regular expression based approach for this type of tasks. You can do this easily using indexOf
. Regular expressions for these patterns become really complicated and un-readable.
var pattern = '0123456789012345789' //to match circular sequence as well.
if (pattern.indexOf(input) == -1)
console.log('good input')
else
console.log('bad input')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With