删除URL输入字段验证但仅接受不带https的URL

问题描述 投票:0回答:1

我想在输入字段中接受URL。但我不关心https://https://。我只想删除此验证。但它应该只接受URL

像这样的例子www.example.comexample.com应该是可以接受的。

<form action="" method="POST" class="form-box d-flex justify-content-between" enctype="multipart/form-data">                            
    <input type="url" class="form-control" name="url">
    <button type="submit" class="btn search-btn">Find</button>
</form>
javascript html html5 html-form html-input
1个回答
0
投票

在这里,我为我的问题做了答案。我正在使用正则表达式进行验证。

<input                      
pattern="^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$" 
placeholder="Find your website ranking... Eg - site.com" class="form-control" name="url"
oninvalid="setCustomValidity('Please Enter URL.')"
onchange="try{setCustomValidity('')}catch(e){}"
>

URL Check Regex - Kajoxopy

我正在使用bellow javascript更改验证消息 -

^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
© www.soinside.com 2019 - 2024. All rights reserved.