Code King Code King - 7 months ago 26
Javascript Question

Check if valid steam profile url

I am trying to make a regex that checks if the url a user is posting, are valid.

I have created the following regex:

/https?\:\/steamcommunity\/.com\/profiles|id\/[a-zA-Z0-9]/


But that isn't working. Is there a regex master, here that can tell me what i am doing wrong?

The links i am trying to validate are looking like:


https://steamcommunity.com/profiles/76561198009610232/
https://steamcommunity.com/id/rasmusvejby/


ANSWERE

/(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+/

Answer

Try this regex:

(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+

See this demo:

Regex Demo

The "g" modifier is just so you can see it test it in different strings, but you probably dont need it.

Comments