Search code examples
javascripthtmlcheckvalidity

Matching an input pattern beginning of script


I'm trying to match only GitHub URLs with the following input tag:

<input type="url" id="repoUrl" title="Must be a full URL to a GitHub repository" pattern="^https:\/\/github\.com\/" required>

In regex101 this exact pattern is matching all strings that start with "https://github.com" which is what I want, but the problem is that when I call the checkValidity() method on that input, it only says it's valid if the input is only "https://github.com".

What do I need to change to make this regex work how it works in regex101?


Solution

  • try to add .* in the end of a pattern

    pattern="^https:\/\/github\.com\/.*"