-3

I can't seem to find a regex to use for a website sign-up form that doesn't require users to enter certain characters.

I need a regex which will allow only the following:

a-z
A-Z
0-9
*#_-

There doesn't have to be a number, no required capitals, no required special characters. Spaces are not allowed.

The minimum length is 8, max is 30 but I'm handling that in another part of the code.

falsetru
  • 357,413
  • 63
  • 732
  • 636
spock99
  • 1,182
  • 1
  • 10
  • 32
  • In what regex variety? Perl, .Net, JavaScript, PCRE? There are differences between the implementations. Your question is the equivalent of "Give me a function that will do this" without specifying what language you're using. – Ken White Jan 10 '14 at 03:48
  • 2
    You said you couldn't find a regex to use, but the fact that 4 identical answer sprung up within seconds of each other has determined that you didn't look hard enough. –  Jan 10 '14 at 03:50
  • Learn to google before you ask such questions – Prakash Vishwakarma Jan 10 '14 at 03:54
  • WHAT!? You are regex-ing the password? Saying no to spaces? (maybe at the beginning and end of the string is okay...) Note to self: don't sign up on @spock99's web service. – chuthan20 Jan 10 '14 at 03:58

4 Answers4

2

Maybe you could try to match this:

^[a-zA-Z0-9*#_-]{8,30}$

How it works:

  • everything between ^ and $ means that the entire input has to match the following pattern.
  • [a-zA-Z0-9*#_-] matches a-z or A-Z or * or # or _ or -
  • {8,30} will need the previous rule to match at least 8 times, at max 30 times.
ccjmne
  • 9,333
  • 3
  • 47
  • 62
0

This should do it:

^[a-zA-Z0-9*#_-]{8,30}$
Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

This regex will do what you need in most flavours of regex parser:

^[a-zA-Z0-9*#_-]{8,30}$
0

Try This

^((?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9*#_-]{6,20})$
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115