简体   繁体   中英

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

<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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM