24
Views
3
Comments
Solved
Compare two name fields with validation

I need to compare two "name" input fields where one field contains the entire name and the second field contains the first name and the abbreviation in the middle name with just one letter and entire surname, and I need to buy these fields and validate if the person You typed correctly, which function can I use inside an if or server actions ???
I've already used index(), but index() only compares if the name is identical, and my second name has abbreviations

ex:

Heitor Augusto Campos Bosqueti

Heitor A C Bosqueti

return:

true

---------------------------------------------------------

Heitor Augusto Campos Bosqueti

Heitor Vila Rodolfo

return:

false

2024-05-08 06-29-37
Prince Aadil Khan Panwar
Solution

Hi Heitor Bosqueti

I suggest you to do this thing

1. Apply string split, you will have the list of each element.

2. And try to use find function for the starting letter if both matches then it will revert true. 

But in this case problem is if starting letter is same but rest of text is different then it can make problem.

Hope this helps

Thanks 

Prince

2026-05-19 09-58-29
Lucas Soares
 
MVP
Solution

If it's something at the screen level, it's possible to follow the path mentioned by Prince, using javascript for example:

function compareNames(nomeCompleto, nomeAbreviado) {

  const nomeCompletoArray = nomeCompleto.split("");

  const nomeAbreviadoArray = nomeAbreviado.split("");

  nomeCompletoArray = nomeCompletoArray.filter((caractere) => caractere !== ".");

  nomeAbreviadoArray = nomeAbreviadoArray.filter((caractere) => caractere !== " ");

  for (let i = 0; i < nomeCompletoArray.length; i++) {

    if (nomeCompletoArray[i] !== nomeAbreviadoArray[i]) {

      return false;

    }

  }

  return true;

}

const nomeCompleto = "Lucas Soares Silva";

const nomeAbreviado = "Lucas S. S.";

console.log(compareNames(nomeCompleto, nomeAbreviado)); 
// retornará verdadeiro (true)


2023-09-28 11-27-54
Heitor Augusto Campos Bosqueti

Thank you very much for the information, it helped me a lot :)

2024-05-08 06-29-37
Prince Aadil Khan Panwar
Solution

Hi Heitor Bosqueti

I suggest you to do this thing

1. Apply string split, you will have the list of each element.

2. And try to use find function for the starting letter if both matches then it will revert true. 

But in this case problem is if starting letter is same but rest of text is different then it can make problem.

Hope this helps

Thanks 

Prince

2026-05-19 09-58-29
Lucas Soares
 
MVP
Solution

If it's something at the screen level, it's possible to follow the path mentioned by Prince, using javascript for example:

function compareNames(nomeCompleto, nomeAbreviado) {

  const nomeCompletoArray = nomeCompleto.split("");

  const nomeAbreviadoArray = nomeAbreviado.split("");

  nomeCompletoArray = nomeCompletoArray.filter((caractere) => caractere !== ".");

  nomeAbreviadoArray = nomeAbreviadoArray.filter((caractere) => caractere !== " ");

  for (let i = 0; i < nomeCompletoArray.length; i++) {

    if (nomeCompletoArray[i] !== nomeAbreviadoArray[i]) {

      return false;

    }

  }

  return true;

}

const nomeCompleto = "Lucas Soares Silva";

const nomeAbreviado = "Lucas S. S.";

console.log(compareNames(nomeCompleto, nomeAbreviado)); 
// retornará verdadeiro (true)


2023-09-28 11-27-54
Heitor Augusto Campos Bosqueti

Thank you very much for the information, it helped me a lot :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.