Solved

allowed chars in Javascript

Posted on 2012-04-03
3
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 41
radio button value 3 43
Hidden Field Value 10 33
jqplot Pie Chart - javascript 2 0
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 …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now