Module talk:number utilities

From Wiktionary, the free dictionary
Latest comment: 3 years ago by Sgconlaw in topic Checking for a hexadecimal number
Jump to navigation Jump to search

Checking for a hexadecimal number

[edit]

Hi, @Erutuon, would it be possible to update this module so that it can be used to check whether an input is a hexadecimal number, and then either update {{num}} or create {{hexnum}} to implement it? I would like to update {{color panel}} and need a way to check if the first parameter is a six-digit hexadecimal (that is, a colour expressed as a hex triplet rather than a colour name), and can't think of a convenient way to do this using HTML or Wikitext. I suspect this can be quite easy done using Lua. — SGconlaw (talk) 13:07, 7 October 2020 (UTC)Reply

@Sgconlaw: Yup, that's very easy. I've created the template, and you can use it as {{hexnum|...|digits=6}}, or, if you want to allow empty numbers, {{hexnum|...|allow_empty=1|digits=6}}. It's a little different in that it doesn't return the decimal version of the number as {{num}} does, but I can change that if necessary. (Also, for programmers, {{hexnum}} currently doesn't accept a leading 0x before the hex digits.) — Eru·tuon 19:29, 7 October 2020 (UTC)Reply
@Erutuon: thank you! I've updated {{color panel}}. — SGconlaw (talk) 19:58, 7 October 2020 (UTC)Reply