Regex pattern to match at least 1 number and 1 character in a string
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a regex /^([a-zA-Z0-9]+)$/ this just allows only alphanumerics but also if I insert only number(s) or only character(s) then also it accepts it. I want it to work like the field should accept only alphanumeric values but the value must contain at least both 1 character and 1 number. 回答1: Why not first apply the whole test, and then add individual tests for characters and numbers? Anyway, if you want to do it all in one regexp, use positive lookahead: /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/ 回答2: This RE will do: /^(?:[0-9]+[a-z]|[a