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 Vila Rodolfo
false
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
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)
Thank you very much for the information, it helped me a lot :)