Brauchen Sie Hilfe!
Ich habe hier auf der Website viel gesucht und kann nicht finden, wie ich meine REGEX erstellen kann
([0-9])(?!\d*\0)){5}
5 Ziffern validieren nicht wiederholte Zahlenfolgen!
00000 (False)
11111 (False)
22222 (False)
33333 (False)
Ich möchte, dass Sie es einfach so unten bestätigen.
00001 (Match)
11110 (Match)
22220 (Match)
12345 (Match)
Danke euch allen.
Lösung des Problems
Wie ich die Frage verstehe, ist kein regulärer Ausdruck in PHP erforderlich.
<?php
$arr = ['', '00000','11111','22222','33333','00001','11110','22220','12345', '12234'];
echo '<pre> ltrim + ltrim: ';
foreach($arr as $el) // not 5 times the same digit using ltrim
if (strlen($el) == 5 && ltrim($el, '0..9') === '' && ltrim($el, $el[0])!== '')
echo "$el, ";
echo "\n ctype + ltrim ";
foreach($arr as $el) // not 5 times the same digit using ctype
if (ctype_digit($el) && strlen($el) == 5 && ltrim($el, $el[0])!== '')
echo "$el, ";
echo "\n count_chars: ";
foreach($arr as $el) // 5 different digits using count_chars
if (ctype_digit($el) && count(count_chars($el, 1)) == 5)
echo "$el, ";
echo "\n array_flip: ";
foreach($arr as $el) // 5 differents digits using array_flip
if (strlen($el) == 5 && ctype_digit($el) && count(array_flip(str_split($el))) == 5)
echo("$el, ");
$N = 2;
echo "\n preg_match with N=$N: ";
foreach($arr as $el) // not N digit repeated with preg_match
if (preg_match('#^(?!.*([0-9])\1{'. ($N - 1). '}.*)[0-9]{5}$#', $el))
echo("$el, ");
/*
ltrim + ltrim: 00001, 11110, 22220, 12345, 12234,
ctype + ltrim 00001, 11110, 22220, 12345, 12234,
count_chars: 12345,
array_flip: 12345,
preg_match with N=2: 12345,
*/
Keine Kommentare:
Kommentar veröffentlichen