DEV Community

Dave Mitten
Dave Mitten

Posted on

Passing emails with special characters as a URL query

Right, so straight to it.

You want to pass an email with a special character/s as part of a query in a url using javascript.

Simples.

All we have to do is utilise the function encodeURIComponent.

const email = 'test+1@test.com';
const encoded = encodeURIComponent(email);
const url = `https://url.com/?email=${encoded}`;

console.log(url); // "https://url.com/?email=test%2B1%40test.com"
Enter fullscreen mode Exit fullscreen mode

and voila...problem solved.

Top comments (0)