[英]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. 我使用此正则表达式
/^[-.a-zA-Z\\s]+$/
来匹配仅包含英文字母,破折号和点的任何字符串。
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]+$/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.