Reputation: 913
I am looking for a regex with at least 6 characters (no limit) including at least one digit. No spaces allowed.
I have this this regex:
^(?=.*\d).{4,8}$
However, I don't want to limit to 8 characters.
Upvotes: 3
Views: 4980
Reputation: 627536
a regex with at least 6 characters (no limit) including at least one digit. no spaces allowed.
^(?=\D*\d)\S{6,}$
Or
^(?=\D*\d)[^ ]{6,}$
See demo
^
Start of string(?=\D*\d)
- Must be 1 digit (the lookahead is based on the principle of contrast)\S{6,}
- 6 or more non-whitespaces
[^ ]{6,}
- 6 or more characters other than literal normal spaceTo enable the regex to match more than 6 characters, you only need to adjust the quantifier. See more about limiting quantifiers here.
Upvotes: 7