Solved

allowed chars in Javascript

Posted on 2012-04-03
3
242 Views
Last Modified: 2012-08-13
Greetings

I am trying to limit characters that can be typed in the textbox on an asp.net web page. Only numbers 0-9 and the two alphabets S and T are allowed. small letter s and t can be allowed but changed to uppercase on keypress. Below is what I tried but it doesn't work.

Please assist!

MandyProg
Allowed-keys.txt
0
Comment
Question by:MandyProgza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 112 total points
ID: 37801988
Take a look at this jsfiddle.

The code is:

$("#test").keyup(function() {
    var value = $(this).val().toUpperCase();
    value = value.replace(/[^0-9ST]/g, "");
    if ($(this).val() != value) $(this).val(value);
});

Open in new window

0
 

Author Comment

by:MandyProgza
ID: 37804803
Thanks, but what if I want to check if the first character is either S or T or 1?

Can you modify the code for that?
0
 
LVL 7

Assisted Solution

by:Atique Ansari
Atique Ansari earned 113 total points
ID: 37809815
Above code does replace the code with blank value after accepting it. Its visible on screen that character is removed after being entered in text box.

Go to below URL.

http://jsfiddle.net/attu143/6pMeL/
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question