我尝试仅将 GitHub URL 与以下输入标记相匹配:
<input type="url" id="repoUrl" title="Must be a full URL to a GitHub repository" pattern="^https:\/\/github\.com\/" required>
在 regex101 中,这个确切的模式匹配以“https://github.com ”开头的所有字符串,这正是我想要的,但问题是当我对该输入调用 checkValidity()
方法时,它仅表示输入仅“https://github.com”时有效。
我需要更改什么才能使此正则表达式像在 regex101 中那样工作?
最佳答案
尝试在模式末尾添加.*
pattern="^https:\/\/github\.com\/.*"
关于javascript - 匹配脚本开头的输入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60176227/