How to verify that it is a true text in an HTML form

0

I have a form in HTML and I have a field called nombre . There is some way to validate that the nombre that is written is verdadero and not any text.

For example this one that has Facebook :

    
asked by camera 28.05.2018 в 07:55
source

2 answers

1

Facebook simply what it does is compare the name written by a strong database and indicate if what you wrote was a common word or a certain sequence of characters, when you try to write in the name as a city, you will realize that it does not accept it, or if you write the company-type name it tells you that you create a page.

UPDATE

You could put a possible sequences in a variable and verify if the entered field is found. Here is an example. (Enter, for example, qwerty )

var secuencia="1234567890qwertyuiopasdfghjklzxcvbnm";
function verificar(valor){
  if(secuencia.indexOf(valor)==-1){
     console.log("se envia");
     return true;
   }else{
     console.log("no se envia");
     return false;
   }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form onSubmit="return verificar(campo.value)">
  <input type="text" id="campo">
  <input type="submit"> 
</form>
    
answered by 28.05.2018 в 08:16
0

As indicated by Smir Llorente Facebook what it does is compare it with a database of names. You can either create a database with Names etc ... or if it's something simple, look for a list of names on the Internet and create an Array with those names. In javaScript for example it would be something like this:

var datoIntroducido = document.getElementById('inputNombre'); //Elemento html 
var nombres = ['Pedro','Jose','Julian', 'Marta','Lucia','Jesus']; //Lo mejor serí consultar una base de datos
for (let i = 0; i < nombres.length; i++) {
    if(nombres[i] != datoIntroducido.value){
        alert('El nombre es falso') // envés de un alert muestras el mensaje de la forma que quieras
    }
    
}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="inputNombre" placeholder="Introduce tu nombre">
</body>
</html>
    
answered by 28.05.2018 в 08:40