condition - Regex - Only ONE special char -


i'm working regex created password.

it have respect conditions :

  • 8 characters
  • at least 1 maj (a-z)
  • at least 1 min (a-z)
  • at least 1 digit (0-9)
  • one special char following : .,:;'!@#$%^&*_+=|(){}[?-]/\
  • prohibit following characters : <>`

here regex :

(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?=.*[.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\])(?!.*[<>`]).{8} 

all works fine, now, want accept only 1 special char.

i searched , tried lot of things (with {1} @ end of group example), doesn't work @ ! results aa1;;aaa still matching..

could tell me how can ?

what about:

^(?=.{8}$)(?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?!.*[<>`])([^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]*)[.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\](?1)$

demo

it check length lookahead, makes sure has 1 special char, different before , after it

(?1) reference 1st group pattern, can replace [^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]* if wish or not supported tool

demo

or, while preserving original syntax:

(?=.*[a-z]) (?=.*[a-z]) (?=.*[0-9]) (?!.*[<>`]) (?=[^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]* [.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\] [^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]*$ ) .{8}$

here's compacted version: (?=.*[a-z])(?=.*[a-z])(?=.*[0-9])(?!.*[<>`])(?=[^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]*[.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\][^.,:;'!@#$%^&*_+=|(){}[?\-\]\/\\]*$).{8}$

demo


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -