Regular expression for six characters with at least one digit
1 answer
regular expression with at least 6 characters (no limit), including at least one digit. without spaces.
^(?=\D*\d)\S{6,}$
Or
^(?=\D*\d)[^ ]{6,}$
Watch the demo
-
^
Start of line -
(?=\D*\d)
- must be 1 digit (lookahead is based on contrast principle) -
\S{6,}
- 6 or more non-spaces
OR[^ ]{6,}
- 6 or more characters other than normal space
To enable regex to match more than 6 characters, you only need to adjust the quantifier. See more about limiting quantifiers here .
+5
source to share