### [How to Restrict Special Characters From a Form Field](https://wpforms.com/developers/how-to-restrict-special-characters-from-a-form-field/)

**Published:** March 16, 2021
**Author:** Editorial Team

**Excerpt:** This tutorial will walk you through how to restrict special characters from being entered in your form fields.

**Content:**

Ever wanted to keep those pesky special characters out of specific fields in your forms? Maybe you’re tired of users entering emojis or symbols where they shouldn’t be. Well, in this guide, we’ll walk you through using JavaScript to put a stop to those unwanted characters in fields like **Single Line Text** and **Paragraph**. Let’s dive in and make your forms a little more orderly!

Ever heard of input masks? They’re like wizards for your form fields, giving you the power to control exactly how users enter their information—no coding needed! And guess what? You can even use input masks to keep those unwanted special characters at bay. If you’re intrigued and want to explore more about customizing these masks, we’ve got you covered. Check out this [comprehensive guide](https://wpforms.com/docs/how-to-use-custom-input-masks/ "Using Custom Input Masks") on using custom input masks for all the juicy details.

## Restricting special characters

Ready to take action? First things first, let’s get these snippets onto your site. Below, you’ll find two pieces of code—one to stop those pesky special characters and another to prevent users from pasting into form fields.

If you’re not sure how to add these snippets to your site, don’t worry! We’ve got you covered with a [handy tutorial on adding custom PHP or JavaScript for WPForms](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/ "How to Add Custom PHP or JavaScript for WPForms"). Check it out for step-by-step guidance.

```

/**
 * Restrict special characters from forms fields with special CSS class
 * Apply the class "wpf-char-restrict" to the field to enable.
 *
 * @link https://wpforms.com/developers/how-to-restrict-special-characters-from-a-form-field/
 */
 
function wpf_dev_char_restrict() {
?>

**Categories:** Extending

**Tags:** Javascript, JS

---

