Solved

allowed chars in Javascript

Posted on 2012-04-03
3
240 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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 …
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…

860 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