Skip to content

Instantly share code, notes, and snippets.

@nklatt
Last active February 6, 2024 16:22

Revisions

  1. nklatt revised this gist Feb 6, 2024. No changes.
  2. nklatt created this gist Feb 6, 2024.
    17 changes: 17 additions & 0 deletions dimension-input.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <input pattern="/^(?:(\d+\/[1-9]\d*)|(\d*(?:(\s\d+\/[1-9]\d*)|\.\d+)?))$/">
    <!--
    (?: => non-capturing group, EITHER
    (\d+\/[1-9]\d*) => any number of digits followed by a slash then any number of digits not beginning with 0 (fraction)
    | => OR
    (\d*(?: => zero or more digits followed by non-capturing group, EITHER
    (
    \s => a space
    \d+ => any number of digits
    \/ => a slash
    [1-9]\d* => one or more digits not beginning with 0
    ) => (fraction OR whole + fraction)
    | => OR
    \.\d+ => a decimal point followed by any number of digits (float)
    )?) => zero or one match for that non-capturing group
    )
    -->