2

I'm trying to get one regex that'll do the following:

  • Min length's 6 and max. length 8

  • No white-space characters

  • There is at least one alphabetic character and numeric character

  • Not contains Turkish character (ı,ö,ğ,ç,ş,ü)

Exp (valid pass) ; tester1, TESTER1, 12345a, invalid pass ; tester*,tester%

I've this regex : ^.*(?=^.{6,8}$)(?=.*[a-z])((?=.*\d)|(?=.*[A-Z])|(?=.*[\W])).*$

Can somebody show and teach me how to do this?

2
  • 2
    reminds me to xkcd.com/936 Commented Dec 20, 2012 at 13:34
  • 1
    On a slightly unrelated note, such password policies may be very uncomfortable to users. Are there any serious reasons you only want these characters and this particular length? Commented Dec 20, 2012 at 13:35

1 Answer 1

3

Here we go:

^(?=.*\d)(?=.*[a-zA-Z])[^öÖşŞıİğĞ]{6,8}$
(?=.*\d)    # must contains one digit from 0-9
(?=.*[a-z]) # must contains one lowercase characters or one uppercase characters
.{6,8}       # length at least 6 characters and maximum of 8    

| = OR example : (?=.*\d)|(?=.*[A-Z]) = must contains one digit from 0-9 OR must contains one uppercase characters

Thx @Özkan

[^öÖşŞıİğĞ] doesnot allow the following characters öÖşŞıİğĞ

You can test it here

Sign up to request clarification or add additional context in comments.

8 Comments

Is somebody show and teach me how to do this?, You've done the first, how about the second?
Indent your regex line by four spaces to make it appear as code and e.g. stop hiding the *s.
The OP wants to learn too. An answer on its own isn't much help to a beginner.
Fixed the formatting, try it now @Dmitry and other downvoter.
@GeorgesD also you must delete "." from .{6,8} thank you in advance
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.