Navigate back to the homepage

How to check special characters in string in javascript?

Infinitbility
JavaScript
May 29th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

Today, I’m going to show How do I check special characters in strings in Javascript, here I will use regex expression to check special characters in a string or not.

What is a special character?

Special characters are symbols that do not appear on a keyboard. What are considered special characters and symbols will vary depending on your country, your installed language in Word and your keyboard like [], {}, (), #, @ etc.

Let’s start the today’s tutorial How do you check special characters in strings in JavaScript?

Let’s understand how we can do it

  1. Create constant of regex expression
  2. Use the regex with javascript test function
  3. Console which string contains special characters and which not
1// Create constant of regex expression
2const format = /[ `[email protected]#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
3
4// Use regex with javascript test function
5// Console which string contains special characters and which not
6format.test("Hello ( Greetings )"); // true
7format.test("Infinitbility"); // false

The above program is the simplest way to check string contains special characters or not, To validate our regex I have passed both case string invalid and valid string, let’s check the output.

javascript, check special characters in string example
javascript, check special characters in string example

I hope it’s help you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to check if a string is a pangram in JavaScript?

Example of check if a string is a pangram in javascript with step by step guide.

May 28th, 2022 · 1 min read

How to check if two strings are anagrams of each other in Javascript?

Example of check if two strings are anagrams of each other in javascript with step by step guide.

May 28th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]