【问题标题】:Matching an input pattern beginning of script匹配脚本开头的输入模式
【发布时间】:2020-02-11 19:40:17
【问题描述】:

我正在尝试仅将 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 中正常工作?

【问题讨论】:

    标签: javascript html checkvalidity


    【解决方案1】:

    尝试在模式末尾添加.*

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

    【讨论】:

    • 谢谢,这正是我所需要的!!我会尽快接受答案!
    猜你喜欢
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 2014-10-01
    相关资源
    最近更新 更多