DEV Community

Dave Mitten
Dave Mitten

Posted on

1

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)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay