Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:16:07+00:00 2026-06-09T08:16:07+00:00

I need to restrict input of special characters (like /, \) as well as

  • 0

I need to restrict input of special characters (like “/”, “\”) as well as “$” (shift+4), “#”(shift+3), but also need to allow capital characters like “A” (shift+a), etc.

Below code works, but I am not restrict “$” and all (from “shift+0” to “shift+9”) as I’m allowing “shift”, Give me some response how to do that,

HTML

<input type="text" id="txtboxToFilter" />

Jquery

<script type="text/javascript" language="javascript">
$(document).ready(function () {
    $("#txtboxToFilter").keydown(function (event) {
        // Allow: backspace, delete, tab, escape, and enter
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
        // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) ||
        // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39)) {
            // let it happen, don't do anything
            return;
        }
        else {
            // stop the keypress for special character "/", "\"
            if (event.keyCode >= 190) {
                event.preventDefault();
            }
        }
    });
});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:16:08+00:00Added an answer on June 9, 2026 at 8:16 am

    As mentioned in the comment, if you want to prevent the use of specific characters, you should attack the problem on the character level, and not try to restrict the use of specific keys. I would do something like in this fiddle. I am using a regular expression to replace all occurrences of unwanted characters. Because interrupting the user when typing is a bit odd, I used change() which is triggered when the text field loses the focus.

    $("#text").change(function() {
        $("#text").val($("#text").val().replace(/\\|\//g, ""));
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some regular expressions help. So far I have my code working to allow
I have the program and I need to restrict it. But I don't know
I have an edited text getting name as user input. I need to restrict
I need to restrict an input so that the user can only enter dollar
I need to restrict the development users from creating new schedules for SQL Agent
I need to restrict users in my application to login from a one computer
I need to restrict user access to filebrowser using permissions. For example, only users
I query my Database using NHibernate. Now I need to restrict the data being
i have created a process using the Process class. now i need to restrict
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.