Since this question is tagged php, I'll provide a demo in php, but the patterns will work with javascript as well (no digit-sorting necessary). My second pattern in the method allows for non-consecutive repetitions of a digit.
Code: (Demo)
$tests=['1234567890'=>'bad start',
'81234567890'=>'too long',
'1211211199'=>'bad start, six repeats',
'1111112233'=>'bad start, six repeats',
'2111111222'=>'bad start, six repeats',
'8221111111'=>'seven repeats',
'1211121212'=>'six repeats',
'9999999999'=>'ten repeats',
'8901234567'=>'valid',
'7677677677'=>'seven repeats',
'8888833333'=>'valid',
'9112345789'=>'valid',
'9444449555'=>'valid',
'6666655544'=>'bad start'];
foreach($tests as $test=>$prediction){
echo "$test ";
if(preg_match('/^[7-9]\d{9}$/',$test) && !preg_match('/(\d)(?=(?:\d*\1){5})/',$test)){
echo "pass";
}else{
echo "fail";
}
echo " \t($prediction)\n";
}
Output:
1234567890 fail (bad start)
81234567890 fail (too long)
1211211199 fail (bad start, six repeats)
1111112233 fail (bad start, six repeats)
2111111222 fail (bad start, six repeats)
8221111111 fail (seven repeats)
1211121212 fail (six repeats)
9999999999 fail (ten repeats)
8901234567 pass (valid)
7677677677 fail (seven repeats)
8888833333 pass (valid)
9112345789 pass (valid)
9444449555 pass (valid)
6666655544 fail (bad start)