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

137
Visualizações
Regex string contain just digits and *,#,+ in javascript

I am trying to implement a function in Javascript that verify a string. The pattern i must to do is contain only digits charactor, *, # and +. For example:

+182031203
+12312312312*#
+2131*1231#
*12312+#
#123*########

I tried alot of thing like

/^[\d]{1,}[*,#,+]{1,}$

but it's doesn't work. I am not sure that i understand good in regex. Please help.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I think you want the pattern ^[0-9*#+]+$:

var inputs = ["+182031203", "+12312312312*#", "+2131*1231#", "12312+#", "#123########"];
for (var i=0; i < inputs.length; ++i) {
    console.log(inputs[i] + " => " + /^[0-9*#+]+$/.test(inputs[i]));
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Using Regex101

/^[0-9\*\#\+]+$/g

0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive) * matches the character * with index 4210 (2A16 or 528) literally (case sensitive) # matches the character # with index 3510 (2316 or 438) literally (case sensitive) + matches the character + with index 4310 (2B16 or 538) literally (case sensitive)

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this regular expression:

const rxDigitsAndSomeOtherCharacters = /^(\d+|[*#]+)+$/;

Breaking it down:

  • ^ start-of-text, followed by
  • ( a [capturing] group, consisting of
    • \d+ one or more digits
    • | or...
    • [*#+]+ one ore more of *, # or +
  • )+, the [capturing] group being repeated 1 or more times, and followed by
  • $ end-of-text
about 4 years ago · Juan Pablo Isaza 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