Answers for "how to check if username already exists in database using javascript"

0

how to check if username already exists in database using javascript

<form onsubmit="return validacija()">
  <table>
    <tr>
      <td>Username:</td>
      <td><input type="text" id="user" name="user" list="list"></td>
      <datalist id="list">
                    <option value="Tilen">
                    <option value="Marko">
                    <option value="Teja">
                    <option value="Tisa">
                    <option value="Rok">
                    <option value="Luka">
                    <option value="Mojca">
                </datalist>
    </tr>
  </table>
</form>
Posted by: Guest on July-31-2021
0

how to check if username already exists in database using javascript

function validacija() {

  let user = document.getElementById('user');
  let listOptions = document.querySelectorAll("#list option");


  if (user.value.length <= 20 && user.value.length >= 3) {} else {
    alert("Username has to be between 3-20 characters.")
  }


  for (let i = 0; i < listOptions.length; i++) {
    if (listOptions[i].value === user.value) {
      alert('The name already exist')
    }
  }
  return false;
}
Posted by: Guest on July-31-2021

Code answers related to "how to check if username already exists in database using javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language