I need regular expression for validating a hashtag. Each hashtag should starts with hashtag(“#”).
I have been trying with this regex
/#[a-zA-z0-9]/ but it is accepting invalid inputs also.
Any suggestions for how to do it?
There are 2 issues:
[A-z]allows more than just letter chars (
[, , ], ^, _, `)
- There is no quantifier after the character class and it only matches 1 char
You might also need anchors (
$) if you want to have a full string match.
See the regex demo.