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

139
Views
Regex to allow only any character from a-z both lower and upper, any number and special characters . -_ only

I have a requirement where we need to add find out regex pattern where user can enter below combinations only.

  1. It should be any character from a-z both lower and upper,
  2. Any number from 0-9
  3. Special characters . -_ only.

we have used below regex pattern..

/^(?=.*?[a-zA-Z0-9.-_])+$/

Can someone please help on this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A - has different meanings in a character class depending on its position

At the end or at the start it's a literal: [._-] contains the three literals ., _ and -

Somewhere else, it's a range: [.-_] is a range from . to _.

You can use 4 regexes to check the strings

function check(str) {
  return /^[a-zA-Z0-9._-]+$/.test(str) && /[a-zA-Z]/.test(str) && /[0-9]/.test(str) && /[._-]/.test(str);
}

const str1 = 'aA5.-_';
console.log(check(str1));
const str2 = 'aA5';
console.log(check(str2));
const str3 = 'aA5.-_+';
console.log(check(str3));

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!