Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!