简体   繁体   中英

Regular Expression for at least one character and one number

I want a regex in which user have to type at least one character and one number in password field.

Right now I'm using using this:

^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$ 

but it is not working properly.

Please help.

Hey Try this expression

^\d*[a-zA-Z][a-zA-Z0-9]*$
  • Zero or more digits;
  • One alpha character;
  • Zero or more alphanumeric characters.

Try a few tests and you'll see this'll pass any alphanumeric string where at least one non-numeric character is required.

use below regex:

/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/

demo: http://jsfiddle.net/nn92H/

尝试这个 :

 ^.*(?=.{1,10})(?=.*\d)(?=.*[a-zA-Z]).*$

Try this

// at least one number, one character
// at least six characters
var re = /(?=.*\d)(?=.*)(?=.*).{6,}/;
return re.test(str);

这将标识一个数字,后跟一个字母,或者一个字母,后跟一个数字,中间有任意数量的非数字/字母字符。

/([0-9].*[a-zA-Z])|([a-zA-Z].*[0-9])/

This'll work:

(?=.*\d)(?=.*[A-Z]) //with 'i' flag

Demo Here

This Page contains many password regex . go through it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM