regex - Password validation with regular expression -
can 1 me in creating regular expression password validation following conditions :
numbers/digits not allowed @ beginning , end must in middle of string
min 6, max 10 characters long
special character should not allowed
at least 1 digit , 2 characters mandatory.
correct format- ab21cd, stack12flow incorrect format- stack123, 123stack
here pattern
\a[^0-9].*[^0-9]\z
\a
means start of string. [^0-9]
means except numbers. .*
means length of characters. can words , digits or signs. \z
means end of string.again [^0-9]
means should not end numbers
if want minimum 6 , maximum 10 characters this
^[^0-9].{4,8}[^0-9]\z
.
character. {4,8}
specifies minimum , maximum number of .
occurrence . since have 2 characters @ first , last of string pattern accepts when put 4+2
characters or maximum 8+2
characters.
based on comment.
(?=\a\w{6,10}\z)(?!\a\d|.*\d\z|.*_)(?=.*\d)
(?=include)
positive ahead. means regex must match part include
.
(?!exclude)
negative ahead. means regex must not match part exclude
.
so (?=\a\w{6,10}\z)
means regex must have 6 10 \w
characters. \w
can numbers , words , underscore _
.
(?!\a\d|.*\d\z|.*_)
means regex must not have digit @ first (\a\d
) or (|
) end of string (.*\d\z
). must not have _
(|.*_
).
(?=.*\d)
means regex must atleast match 1 digit.
you dont need check string must have atleast 2 words. because string must started , end 2 words.
Comments
Post a Comment