Javascript Regex to match only a single occurrence no more or less

You can do this

/^[^-]+-[^-]+$/

^ depicts the start of the string

$ depicts the end of the string

[^-]+ matches 1 to many characters except -

Leave a Comment