简体   繁体   中英

JavaScript Regular Expression to match digits too

I use this regex /^[-.a-zA-Z\\s]+$/ to match any string contains only English letters, dashes and dots.

I would like to modify it to make it match any digit too.

so all these strings will be accepted:

first
first-floor
1st floor
floor No. 1

how can I do this ?

只需在您的角色类中添加数字:

/^[-.a-zA-Z\d\s]+$/

您还可以编写:

 /^[-.a-zA-Z0-9\s]+$/

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