Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

429
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda