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

202
Views
how to allow only 1 forward slash in regex expression

I have regex expression to check alpha numeric inputs max 16 which is following

^[a-zA-Z0-9]{0,16}$

how i can modify this to check it should have only 1 forward slash. like

aas/as12

12/saad

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

0

You can use:

^(?!.{17})[a-z\d]+\/[a-z\d]+$

See an online demo


  • ^ - Start-line anchor;
  • (?!.{17}) - Negative lookahead to prevent 17 characters (other than newline). This can be more precise and you may want to change into 18 depending if you count the forward slash on top of the 16 alphanumeric characters.
  • [a-z\d]+\/[a-z\d]+ - 1+ Alphanumeric chars, a single literal forward slash and again 1+ alphanumeric chars.
  • $ - End-line anchor.

Note that I used case-insensitive matches, meaning your JS-pattern would look like:

/^(?!.{17})[a-z\d]+\/[a-z\d]+$/gi

const regex = /^(?!.{17})[a-z\d]+\/[a-z\d]+$/i;
[
  "aas/as12",
  "12/saad",
  "/"
].forEach(s =>
  console.log(`${s} --> ${regex.test(s)}`)
)

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!