Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for sequential numbers like 12345 or 456789

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}$/;
like image 446
Shijin TR Avatar asked Dec 04 '22 00:12

Shijin TR


1 Answers

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')
like image 128
Narendra Yadala Avatar answered Jan 18 '23 23:01

Narendra Yadala