“#” should be escaped to “%23”. But generally it’s not something you do by hand, most programming languages have a simple way to do it (sometimes it might be an external library).
For example, if you’re using PHP you should use urlencode, if you’re using JavaScript you should use encodeURIComponent.