He corregido algunos errores después de probarlo.
Código Delphi
[-]
function ExpresionValida (s : string) : boolean;
var
i : integer;
begin
Result := False;
if ((Length(s) = 10) or (Length(s) = 11) or (Length(s) = 15) or (Length(s) = 16) or (Length(s) = 18)) then
begin
Result := True;
for i := 1 to Length(s) do
begin
if not (s[i] in ['0'..'9']) then
Result := False;
end;
end;
if (not Result) then
begin
if ((Length(s) >= 10) and (Length(s) <= 50)) then
begin
Result := True;
for i := 1 to Length(s) do
begin
if ((not (s[i] in ['A'..'Z'])) and (not (s[i] in ['0'..'9'])) and (s[i] = '_')) then
Result := False;
end;
end;
end;
end;
Código:
[2018-09-17 10:53:07.856] 123456789 Valido False
[2018-09-17 10:53:07.856] 1234567890 Valido True
[2018-09-17 10:53:07.856] 12345678901 Valido True
[2018-09-17 10:53:07.856] 123456789012 Valido True
[2018-09-17 10:53:07.856] 1234567890123 Valido True
[2018-09-17 10:53:07.856] 12345678901234 Valido True
[2018-09-17 10:53:07.856] 123456789012345 Valido True
[2018-09-17 10:53:07.856] 1234567890123456 Valido True
[2018-09-17 10:53:07.856] 12345678901234567 Valido True
[2018-09-17 10:53:07.856] 123456789012345678 Valido True
[2018-09-17 10:53:07.856] 1234567890123456789 Valido True
[2018-09-17 10:53:07.866] 12345678901234567890 Valido True
[2018-09-17 10:53:07.866] A23456789 Valido False
[2018-09-17 10:53:07.866] A234567890 Valido True
[2018-09-17 10:53:07.866] A2345678901 Valido True
[2018-09-17 10:53:07.866] A23456789012 Valido True
[2018-09-17 10:53:07.866] A234567890123 Valido True
[2018-09-17 10:53:07.866] A2345678901234 Valido True
[2018-09-17 10:53:07.866] A23456789012345 Valido True
[2018-09-17 10:53:07.866] A234567890123456 Valido True
[2018-09-17 10:53:07.866] A2345678901234567 Valido True
[2018-09-17 10:53:07.866] A23456789012345678 Valido True
[2018-09-17 10:53:07.866] A234567890123456789 Valido True
[2018-09-17 10:53:07.866] A23456789012345678901234567890123456789012345678901 Valido False