简体   繁体   中英

Regular Expression For At Least One Number

How would you create a regular expression for a value that should contain at least one number? The user can enter any special character, letter etc., but should contain at least one number.

I tried with pattern="[\\w+]{6,20}" and

(?=.*\d)(*[a-z])(*[A-Z]).{6,20}

Neither are working.

Try using this pattern

.*[0-9].*

For 6 to 20 use this

^(?=.*\d).{6,20}$ 

Use this Regex

An easier solution would be to retain your existing regex, then create two new regexes to test for your "at least one alphabetic" and "at least one numeric".

So, test for this :-

 /^([a-zA-Z0-9]+)$/

Then this :-

 /\d{1}/

Then this :-

 /[A-Z]{1}/i

您可以使用此模式:

/^(?=.{6,20}$)\D*\d/

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