Search code examples
htmlregular-language

Regular expression in HTML - Command OR


I have this:

<input type="text" name="funkce<%=i %>" value="" size="20" data-toogle="tooltip" title="Vlož hodnoty a-z o maximální délce 3 znaky." style="width: 50px; padding: 2px" required maxlength="3"  pattern="([a-z]{1,3})|(([a-z]{1}[\s,]+)*[a-z]{1})" />

It is not working I need control input for two types string. I need insert example "a,b,c" or "abc", but or (|) in pattern is not working :(


Solution

  • Your pattern is working. It is checked onsubmit, not onkeydown nor onkeypress.

    However, the pattern is nondeterministic. It should be writen in such a way that every character is matched by at most one subpattern. In this case, deterministic version is: [a-z](([a-z]{1,2})|([\s,]+[a-z])*)

    Also maxlength="3" will not work with input a,b,c.