Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 4
    Welcome to StackOverflow. At StackOverflow, it is expected that you read everyone else's answers before posting your own answer. Both of your solutions work, but they are nearly word-word duplicates of Ariel's answer at the top of this page. While you may have come up with your solution on your own, you should never post your solution an answer if someone else has already beaten you to it. P.S. There isn't really any "or." Both of your solutions function identical in all cases, except the former solution is better because it takes up one less character (in the minified file). Commented Jun 14, 2018 at 16:23
  • this answer could be improved by discussing the difference between .test and .match, and when to use each one, or at least referencing an answer that does, like this one: stackoverflow.com/questions/10940137/… Commented Sep 1, 2021 at 23:35