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
custom username with javascript validation

I want users to create a username with some conditions.

The username must be 6 or more characters in length.

It can contain an underscore but it's not required.

It can contain a-z or A-Z or 0-9 characters.

currently, this is what I put for validation

var usern=  /^[a-zA-Z0-9_]{6,}[a-zA-Z]+[0-9]*$/;

but the username is not working if it is joseph_123, joseph123_ or jose123

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

0

You can use the \w Metacharacter. Matches a-z, A-Z, 0-9, and the _ (underscore).

^\w{6,}$

const TESTS = ['joseph_123', 'joseph123_', 'jose123' ,'1234', 'á123456', '1223456á', 'abc-def']

TESTS.forEach((uname) => {
  console.info(uname + ': ' + uname.match(/^\w{6,}$/))
})

https://www.w3schools.com/jsref/jsref_regexp_wordchar.asp

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!