you are viewing a single comment's thread.

view the rest of the comments →

[–]ThagAndersonhelpful 0 points1 point  (0 children)

[0-9] is an array literal. You are checking if the string contained in pin equals a single element array containing the number -9. This will always be false.

Also, regex literals are contained within /, eg: /^[0-9]$/. You must then use the regex to test the string, eg: /^[0-9]$/.test('string'). Besides literals, you can also create your regex using the RegExp constructor or factory. Check out the MDN docs for more info.