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

425
Vistas
How to restrict input field from accepting special characters in Angular?

I have a input field that should not be blank and should not allow special characters.

I have something like this for validation:

if (value === '' || !value.trim()) {
      this.invalidNameFeedback = 'This field can not be blank.';
      return false;
    } else if (!value.match(/[\p{Letter}\p{Mark}]+/gu)) {
      this.invalidNameFeedback = 'This field can not contain special characters.';
      return false;
    }

This allows special characters when entered with alphabets or numbers. I dont want allow special characters at all.

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

0

You could check the whole value to only match a selected character class and use for example .test()

^[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]+$

See the regex matches.

Example

if (value === '' || !value.trim()) {
    this.invalidNameFeedback = 'This field can not be blank.';
    return false;
} else if (!/^[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]+$/u.test(value)) {
    this.invalidNameFeedback = 'This field can not contain special characters.';
    return false;
}
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