[erlang-questions] Validating binaries
Roger Lipscombe
roger@REDACTED
Tue Aug 11 16:49:41 CEST 2015
On 11 August 2015 at 15:39, Roger Lipscombe <roger@REDACTED> wrote:
> Simple question: what's the most efficient way to validate that a
> binary value is of a certain length, and contains only certain
> characters?
>
> I've got the following:
[snip]
It might be worth pointing out that I only have to deal with the
following combinations: 16 lower-case hex characters or 24 upper-case
hex characters. ASCII encoding. So would something like the following
be better?
validate_lower_case_hex_16(<<C1:8, C2:8, ...)
when
(C1 >= $0, C1 =< $9; C1 >= $a, C1 =< $f),
(C2 >= $0, C2 =< $9; C2 >= $a, C2 =< $f),
... % lots of repitition here
->
Value;
More information about the erlang-questions
mailing list