logo
Tags down

shadow

Javascript checking if username already exists(duplicate)


By : Daniel Wilson
Date : October 18 2020, 08:10 AM
hop of those help? You can get all the options using querySelector, iterate over them and compare then with user.value. Also you need list="polje_imen" in the input element.
code :
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;
}
<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>
function validacija() {

  let user = document.getElementById('user');
  let listNames = ["Tilen","Marko","Teja","Tisa","Rok","Luka","Mojca"];


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


  for (let i = 0; i < listNames.length; i++) {
    if (listNames[i] === user.value) {
      alert('The name already exist')
    }
  }
  return false;
}
<form onsubmit="return validacija()">
  <table>
    <tr>
      <td>Username:</td>
      <td><input type="text" id="user" name="user"></td>
    </tr>
  </table>
</form>


Share : facebook icon twitter icon

Checking to see if username exists


By : Dan Horoshko
Date : March 29 2020, 07:55 AM
With these it helps I am beginning work on coding a site and at the moment I am doing a user creation page. All the validation works fine, but I am unsure what to put into the checkUsername method in order to verify that the username does not already exist. Below is my ASP.NET code. , Custom validation methods need the following method signature:
code :
void checkUsername(object source, ServerValidateEventArgs args)
args.IsValid = true; 

Checking if Username already exists


By : Amir Hadi Pouriamane
Date : March 29 2020, 07:55 AM
Any of those help Ok, I'll post my comment as an answer.
Your IF statement is evaluating the incorrect variable. It should be evaluating $countUsername, not $checkUsername.
code :
if ($countUsername != 0)
{
    $errors[] = 'Username is already taken';
}
Collation = latin1_general_cs    (cs = case sensitive)

Checking if username already exists within the databasae


By : Matthew
Date : March 29 2020, 07:55 AM
Does that help As a good pratice, try to keep your persistence using Parameters to avoid SQL Injection.
Try something liek this:
code :
private void btnSignupNew_Click(object sender, EventArgs e)
{

   if (txtUsername.Text == "")
   {
       errorUsername.SetError(txtUsername, "Enter A Username");
   }
   else if (txtPassword.Text == "")
   {
       errorPassword.SetError(txtPassword, "Enter A Valid Password");
   }
   else
   {
        using (SqlConnection con = new SqlConnection("Data Source=etc")) 
        {
            con.Open();

            bool exists = false;

            // create a command to check if the username exists
            using (SqlCommand cmd = new SqlCommand("select count(*) from [User] where UserName = @UserName", con))
            {
                cmd.Parameters.AddWithValue("UserName", txtUsername.Text);
                exists = (int)cmd.ExecuteScalar() > 0;
            }

            // if exists, show a message error
            if (exists)
                errorPassword.SetError(txtUsername, "This username has been using by another user.");
            else 
            {
                            // does not exists, so, persist the user
                using (SqlCommand cmd = new SqlCommand("INSERT INTO [User] values (@Forname, @Surname, @Username, @Password)", con))
                {
                    cmd.Parameters.AddWithValue("Forname", txtForname.Text);
                    cmd.Parameters.AddWithValue("Surname", txtSurname.Text);
                    cmd.Parameters.AddWithValue("UserName", txtUsername.Text);
                    cmd.Parameters.AddWithValue("Password", txtPassword.Text);

                    cmd.ExecuteNonQuery();
                }               
            }

            con.Close();
        }   
    }
}

Checking to see if username exists in firebase DB.


By : Mondher Ben
Date : March 29 2020, 07:55 AM
hop of those help? The behavior you're seeing is indeed intended. Since you're attaching an observer, the first if block is being run for a unique name, but within that block, you're setting a value.
This triggers the callback again, which this time, will run through the else block.

checking if username exists in mysql through javascript with input.onkeyup


By : Amund Tenstad
Date : October 13 2020, 09:00 PM
will help you Okay, a bunch of issues I see here. Firstly, you're attempting to perform an asynchronous operation in a synchronous context.
Disclaimer: I'm not a PHP person (mysql_query seems to be PHP?), so if that's what you're trying to do, I may not be your guy. If this is not the case - if you expect mysql_query to be a function - you're going to need to have that defined somewhere else.
code :
//firstly, let's assume mysql_query is an async JavaScript function that you've defined.
mysql_query(`SELECT * FROM users WHERE username = ${input.value}`, function(err, response){
  if(err){
    alert('ERROR CHECKING NAMES!');
  }else if (response.length){
    //assume that if the query returns anything, that means it found a matching (==duplicate) name
    alert('NAME ALREADY EXISTS!');
  }else{
    //do nothing!
  }
});
myTimer = null;
someThing.onkeyup = function(e){
  if(myTimer){
    //myTimer was previously defined. Cancel its sending and then
    clearInterval(myTimer)
  }
  //start a new timer
  setTimeout(function(){
    doSomeAPICall()
  },500)//or whatever milliseconds
}
Related Posts Related Posts :
  • Session.cookies.get_dict() return an empty dictionary
  • Performing logical operation inside Higher Order Component on prop set
  • how to force the browser to run the javascript every time it called
  • REGEX get all content after a series of special characters
  • deduce amount issue, not the same value foreach execute
  • Regex to get individual function bodies from group of functions
  • Stop animation from executing if coming from an internal link
  • How to retrieve total of "else if"
  • Multiple JS slideshows on one page
  • Importing async functions in Javascript
  • How to handle state on array of checkboxes?
  • React Native - Redux ~ Props updating when not getting called
  • Fast way to add elements into an Uint8ClampedArray typed array
  • How to retrieve values from a checkbox group generated dinamically with jquery when page loads
  • Progress bar between two dates (fetch "var" from script), HTML
  • Why do Every time I start my function I get NaN
  • Angular routing change in url
  • Javascript - Change symbol on embedded tradingview script.text
  • How to select specific option?
  • Checking booleans from multiple arrays simultaneously, without multiple if statements
  • How to get a subarray?
  • Javascript JSON woes
  • Use Jquery animate to have a button move a box to the next corner
  • Why is this JavaScript not interpreted as a code block when semi-colon is used?
  • Reload another page when I click on button
  • Should functions that call a callback function be bound?
  • For loop print in single line separated by spaces - JS
  • Add Javascript Variable into asp-route-data
  • Two different POST requests are making use of the same variable
  • Convert JSOn object into a flat JSON Array
  • Manually adding to an HTML range input gives unexpected results
  • Refreshing component after making api call Reactjs
  • Google App Script : Finding The Last Blank Row
  • I cant for the life of me figure out whats wrong with this script
  • Order divs by ID in Javascript
  • set new element class property value
  • How to pass a java variable to a different jsp page containing javascript?
  • Locked it method in chai
  • React JS : history.push is not a function error and it isn't navigating to a different page onclick of swal
  • How can i set timeout for localstorage for Angular 2+?
  • Must use destructuring props assignment
  • Jest Compared values have no visual difference. when testing arrays
  • Uncaught Error: #90211 ExtensionName Error - Node.JS, Heroku, JavaScript App using FusionCharts
  • Is it possible in firebase auth to update user and custom claims at the same time node?
  • Filter out capitalized letters
  • Yet Another Google Firebase Error "Function returned undefined, expected Promise or value"
  • How do I address method in a Vue.js component from inside callback function?
  • What is the name of this feature in JavaScript?
  • Vue js using scope-slot and trying to use a property from within but having no visibility
  • Dynamic javascript table won't display iterations from array
  • How to start/end smoke.js animation by clicking a nav button?
  • Map array of strings as object properties
  • Appending new inputs with JS wipes previous ones
  • Chai Request With URL instead of JS File
  • React Jest Async Tests
  • Unordered list bullet not showing at an expected location
  • How to create an array from an object?
  • How to get prefix name from html tag
  • javascript - Simulate a click event (tap with finger) on a button in iOS
  • How to get the value of checkboxes in a kendo grid
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org