I'm new to JS and couldn't find the answer anywhere in the web so I got to ask here !
I want to check if the input contains one of the substring in an array, if not, form submission got to be stopped right away and page load avoided.
**Inputs examples:**
"http//:www.indeed.com" IS validated ---
"http//:www.linkedin.com" IS validated ---
"http//:www.google.com" IS NOT validated ---
<form name="form1" action="index.php" method="post">
<input id="link" required type="text" name="link">
<button type="submit" onsubmit="javascript:checklink();" class="submit">
go !
</button>
</form>
function checklink() {
var arr = ['indeed.', 'linkedin.'];
var i;
var input = document.getElementById("link").value;
for (i = 0; i < arr.length; i++) {
if ( arr[i] !== input) {
alert(arr[i] +"Wrong URL");
return false;
}
else {return true}
}
}
Any idea ? Thanks a lot in advance !