0

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

<p>
    <label for="firstName">Link:</label>
    <input type="text" name="Link" placeholder="only mega.nz links"> 
</p>
Lukasz Koziara
  • 4,274
  • 5
  • 32
  • 43

1 Answers1

0

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>
MrSmile
  • 1,217
  • 2
  • 12
  • 20
  • excuse me what's #Link –  Jun 16 '18 at 22:50
  • I'm pretty confused where do i put exactly the script ? –  Jun 16 '18 at 22:54
  • You must wrap up the javascript code in – MrSmile Jun 17 '18 at 05:54