1function validacija() {
2
3 let user = document.getElementById('user');
4 let listOptions = document.querySelectorAll("#list option");
5
6
7 if (user.value.length <= 20 && user.value.length >= 3) {} else {
8 alert("Username has to be between 3-20 characters.")
9 }
10
11
12 for (let i = 0; i < listOptions.length; i++) {
13 if (listOptions[i].value === user.value) {
14 alert('The name already exist')
15 }
16 }
17 return false;
18}
1<form onsubmit="return validacija()">
2 <table>
3 <tr>
4 <td>Username:</td>
5 <td><input type="text" id="user" name="user" list="list"></td>
6 <datalist id="list">
7 <option value="Tilen">
8 <option value="Marko">
9 <option value="Teja">
10 <option value="Tisa">
11 <option value="Rok">
12 <option value="Luka">
13 <option value="Mojca">
14 </datalist>
15 </tr>
16 </table>
17</form>