Reputation:
Why does this not work? I need it to find if it starts with a number, and to take it even further, I need it to do this with multiple numbers. For example, if it starts with 1259823 it will do this code. I imagine it's probably because a lot of things can fall in this category, but is there any workaround?
Edit: it throws an error because startsWith
must not be a regular expression.
Workaround is using .test();
Upvotes: 2
Views: 590
Reputation: 89374
String#startsWith
only accepts a string argument. You can use ^
anchor to match the start of the string and use RegExp#test
to verify the input.
if(/^[0-9]/.test(msg.content)){
//...
}
Upvotes: 2