How to tag users using HTML & Javascript like Twitter



   I am making a social media site, and I want to tag users like this: @Joko. What I want to do is create a javascript code that will select all the text on the body, and if it includes the string "@" followed by a name, then to make a url. 


"@username"  ---> "@username"

I want to create a javascript function to replace all "@username" with "@username". How can I do this?

People Joined:

  • @RedMan2
Log in to comment

1 years, 137 days ago

maybe something like "text.replace(\@[a-z0-0]+\gi, what you want to replace it with here)" basically I use a regular expression to search for anything with an "@" symbol and then letters and numbers following. Look up "regexr" and you get this super handy thing for creating things like that, with a cheatsheat and things