How do I test whether a string contains only numbers and spaces using RegEx?
ie
Pretty loose, but this meets my requirements.
Suggestions?
How about /^[\\d ]+$/
? If it needs to start and end with a digit, /^\\d[\\d ]*\\d$/
should do it.
[0-9]
<-- this means any single digit between 0 and 9 [0-9 ]
<-- this means any single digit between 0 and 9, or a space [0-9 ]{1,}
<-- this means any single digit between 0 and 9, or a space, 1 or more times [0-9 ]{1,9}
<-- this means any single digit between 0 and 9, or a space, 1 to 9 times 就像是:
\d*|\s+^[A-Za-z]
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.