• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1267
  • Last Modified:

Regex for username

Hello all,

need a pretty simple regex but my head is a bit fuzzy and can't get it working quite right...

what i need is a regex for a user name that accepts a-z, A-Z, 0-9, -, and _ but DOES NOT allow - or _ at the beginning or the end.

I have the first part: /^[a-zA-Z0-9_-]+$/

please help me add the -/_ restriction... thanks!
0
bobbit31
Asked:
bobbit31
  • 2
1 Solution
 
ddrudikCommented:
Not sure how many characters you want to allow in the name, but here's a possible option:
^[a-zA-Z0-9][a-zA-Z0-9_-]*[a-zA-Z0-9]$
0
 
bobbit31Author Commented:
works for me... thanks for the fast response!
0
 
ddrudikCommented:
Thanks for the question and the points.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now