I have a dynamic page set up where artists can create their own pages/profiles. We are trying to make it so artists can’t create the same name as this would result 2 people using one URL (url is based on artist name) and someone would lose control of their profile along the way. To do this we set up a query to check our database to see if there are any artist names that match, if so it will disable the button and give them an error msg. The issue is that this is case sensitive so this allows artists to create the same name (if using caps etc…) is there a way to make this not case sensitive so that it will catch all of the duplicates. I will paste the code below to reference.
any help would be much appreciated! thanks in advance
function doChecks(){ wixData.query("ArtistsProfileData") .eq("artistName", $w("#iptArtistName").value) .limit(1) .find() .then((results) => { if(results.items.length > 0){ $w("#txtMessage").text = "This user name is already taken, please choose another."; $w("#txtMessage").show(); $w("#btnActivate").disable(); } else if($w("#iptArtistName").value.length < 2 || $w("#iptArtistName").value.length > 18){ $w("#txtMessage").text = "Please enter a user name between 2 and 18 characters."; $w("#txtMessage").show(); $w("#btnActivate").disable(); } else { setTimeout('',5000); $w("#btnActivate").enable(); $w("#txtMessage").hide(); } }) } export function iptArtistName_keyPress(event) { setTimeout(doChecks, 50); }
Greetings
I hope that all is well
I'm not master programmer but I had a similar issue where I wanted to ensure that every user that signed on my site had a unique email address and alias (username). After I figured out how to check for duplicates I ran into the case sensitive problem where 'test@test.com' would be different from 'TEST@test.com'.
I forced all things inputed into my site to be lowercase in the database and this helped to keep things simple and avoid duplications in my check
Code forcing input to be all lowercase
//Run all checks and if good, register user to the site $w('#submitButton').onClick(function () { let email = $w('#registerEmail').value.toLowerCase(); //Get user email and turns it all lowercase to enter in the database let password = $w('#registerPassword').value; let alias = $w('#registerAlias').value.toLowerCase(); //Get user alias and turns it all lowercase to enter in the database authentication.register(email, password, { //Created custom 'alias' (username) field in CRM and I capture that data from my form and register it as well contactInfo: { "Alias": alias, }, privacyStatus: "PUBLIC" }) .then( (registrationResult) => { console.log('Registered New User!', registrationResult); //Go to Home page wixLocation.to("/"); }) //.catch((error) => // { // console.error(error); // }); })
Code to check for duplicates in the email or alias. If a user types in the input box and there is already a match then prevent them from submitting.
//Check Duplicate Alias; if duplicate exists show warning and keep email password box disabled export function checkAliasDup(event) { let alias = $w('#registerAlias').value; console.log("Something Updated in Alias box") //Query for Existing Email in Collection; if found, do not allow user to register & generate 'duplication error' wixData.query("MemberInfo") .eq("alias", alias) .find() .then( (results) => { //If the email field already exists; show error if(results.length > 0) { $w("#aliasDupeerror").expand(); $w('#registerEmail').disable(); console.log("Alias Already Exists! Email field disabled!") } else { $w('#registerEmail').enable(); $w('#aliasDupeerror').collapse(); } }) } //Check Duplicate Email; if duplicate exists show warning and kept password box disabled export function checkEmailDup(event) { let email = $w('#registerEmail').value; console.log("Something Updated in Email box") //Query for Existing Email in Collection; if found, do not allow user to register & generate 'duplication error' wixData.query("MemberInfo") .eq("email", email) .find() .then( (results) => { //If the email field already exists; show error if(results.length > 0) { $w("#emailDuperror").expand(); $w('#registerPassword').disable(); console.log("Email Already Exists! Password field disabled!") } else { $w('#registerPassword').enable(); $w('#emailDuperror').collapse(); } }) }
Site: https://alvingwallace.wixsite.com/skreen/sign-up
Hope this helps or at least generate an idea :)
Hi @mre1991
Please use .contains() for non case sensitive.