how to check if username already exists in database using javascript

Solutions on MaxInterview for how to check if username already exists in database using javascript by the best coders in the world

showing results for - "how to check if username already exists in database using javascript"
Jan
19 Apr 2018
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}
Luciano
17 Apr 2018
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>