Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
Validating name in visual studio code
var userName = input.question('Please enter your name: '); //Asking User to enter their Name.
while (userName.includes('.')) {
    console.log ("Invalid Name!");
    var userName = input.question('Please enter your name: '); //Asking User to enter their Name.
}

Above code will ask the user his/her name and store it in "userName". Then it will validate using .includes to check unwanted characters and numbers.

I want to validate if userName has numbers or unwanted characters such as "?/.,;'[]{}|&^%@" etc. I have tried using .includes and validate if a name has "." However, I'm not sure how to go about from there to validate the rest.

After the while checks that it contains the unwanted characters, it will re-prompt the user to enter a new name and it will check again until it returns false.

Is there a solution to this?

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

You can use REGEX to search for non-alphabetic or space characters in the string:

userName.search(/^[a-zA-Z\s]+$/)

The response will be 0 or -1. 0 means that no characters except A-Z, a-z and space were found, -1 means the contrary.

Edit: I found similar question with more detailed answers here.

about 4 years ago · Santiago Gelvez Denunciar

0

let chars = /[$&+,:;=?@#|'<>.^*()%!-]/g;
chars.test(UserName)

Use Regular expressions ( Regex ) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda