[英]I cannot succes to make my input text accept only links from a specific website
So what i'm trying to do is to make this input accept only links like as example from mega.nz and if it's recivies any other links from any other website it would refuse and says a message on the top of the page Use Mega.nz and thanks so much for helping 因此,我想做的是使此输入仅接受mega.nz这样的链接,如果它从其他任何网站接收到其他链接,它将拒绝并在页面顶部使用Use Mega表示一条消息。 nz ,非常感谢您的帮助
<p>
<label for="firstName">Link:</label>
<input type="text" name="Link" placeholder="only mega.nz links">
</p>
You can use a simple validation, like this: 您可以使用简单的验证,如下所示:
$("#Link").on('change keydown paste input', function() { var url = $(this).val(); isValid = url.includes("mega.nz"); if(isValid) { $(this).prev("label").removeClass("error"); } else { $(this).prev("label").addClass("error"); } });
label.error { color:#ff0000; font-weight:bold; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p> <label for="Link">Link:</label> <input type="text" id="Link" name="Link" placeholder="only mega.nz links" /> </p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.