Solved

allowed chars in Javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…

895 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

17 Experts available now in Live!

Get 1:1 Help Now