简体   繁体   English

六个字符的正则表达式,至少有一位

[英]Regex for six characters with at least one digit

I am looking for a regex with at least 6 characters (no limit) including at least one digit.我正在寻找一个至少包含 6 个字符(无限制)包括至少一位数字的正则表达式。 No spaces allowed.不允许有空格。

I have this this regex:我有这个正则表达式:

^(?=.*\d).{4,8}$

However, I don't want to limit to 8 characters.但是,我不想限制为 8 个字符。

a regex with at least 6 characters (no limit) including at least one digit.一个至少 6 个字符(无限制)的正则表达式,包括至少一个数字。 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 ) (?=\\D*\\d) - 必须是 1 位(前瞻是基于对比原理
  • \\S{6,} - 6 or more non-whitespaces \\S{6,} - 6 个或更多非空格
    OR或者
    [^ ]{6,} - 6 or more characters other than literal normal space [^ ]{6,} - 6 个或更多字符,而不是文字普通空格

To enable the regex to match more than 6 characters, you only need to adjust the quantifier.要使正则表达式匹配 6 个以上的字符,您只需要调整量词即可。 See more about limiting quantifiers here .在此处查看有关限制量词的更多信息

^(?=.*\\d)([\\w]{6,})$

我认为它应该可以正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 匹配每个 n 位的正则表达式至少有一个数字 1 - Regex to match each n digit has at least one digit 1 正则表达式,删除重复出现的字符,但至少保留一个 - Regex, removing recurring characters but keeping at least one 正则表达式在 JavaScript 中包含至少一个字母和至少 6 个字符长的所有字符 - Regex to include all characters with at least one letter and at least 6 characters long in JavaScript 密码的正则表达式必须至少包含八个字符,至少一个数字以及大小写字母和特殊字符 - Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters 正则表达式:必须至少包含一个数字和字母,但不能包含其他字符/空格 - RegEx: Must have at least one number and letter but no other characters / whitespace 正则表达式接受最少6个字符,至少一个字母和以下至少之一:0123456789-。@ _ - Regex to accept Min 6 characters, at least one letter and at least one of the following: 0123456789-.@_ 字符串的正则表达式模式包含“至少一位数字,并且仅允许两个特殊字符” - Regex pattern for a String contains “at least one digit and allows only two special chars” 密码应至少包含 1 位数字 - ValidateJS 中的正则表达式 - Password should contain at least 1 digit - Regex in ValidateJS 最少 6 个字符的密码 REGEX,至少一个字母和一个数字,可以包含特殊字符 - Password REGEX with min 6 chars, at least one letter and one number and may contain special characters 连续删除特定重复的特殊字符,但每次使用正则表达式至少保留一个? - Removing specific repeated special characters in a row, but keep at least one in each occurrence with regex?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM