Reputation: 2329
The goal is to compose a regex using the .test() or .match() to check if a string contains all numbers.
For example:
So far my regex looks like this:
str.match("^[0-9]*$")
I'm getting null returned
I am also looking for ways to do this using the .test() method which will return true or false.
Any help with working with regex is greatly appreciated.
Upvotes: 0
Views: 109
Reputation: 920
Your regexp is correct. Using regexp literal you will be able to use test:
/^[0-9]*$/.test('10001')
-> true
/^[0-9]*$/.test('10ab001')
-> false
Upvotes: 1