473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to allow only character (a-z) and number(0-9) only in the textbox?

currently i try this code but:
Expand|Select|Wrap|Line Numbers
  1. -->for alphanumeric(allow alphanumeric : a-z,0-9,(symbol))
  2. <asp:textbox onkeypress="if(((event.keyCode>=39)&amp;&amp;(even t.keyCode<=39))){event.returnValue=false;}"
  3. id="txtStfNo" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="440px" Height="60px"></asp:textbox>
  4.  
  5.  
  6.  
  7. <asp:textbox onkeypress="if(((event.keyCode>=39)&amp;&amp;(even t.keyCode<=39))){event.returnValue=false;}"
  8. id="txtccno" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="440px" Height="60px"></asp:textbox>
  9.  
  10.  
  11. --->allow numeric only
  12. <asp:textbox onkeypress="if(((event.keyCode>=32)&amp;&amp;(even t.keyCode<=47))||((event.keyCode>=58)&amp;&amp;(ev ent.keyCode<=254))){event.returnValue=false;}"
  13. id="Textbox1" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="152px"></asp:textbox>
  14.  
  15. ---allow symbol only
  16. <asp:textbox onkeypress="if(((event.keyCode>=48)&amp;&amp;(even t.keyCode<=57))||((event.keyCode>=65)&amp;&amp;(ev ent.keyCode<=90))||((event.keyCode>=97)&amp;&amp;( event.keyCode<=122)) ){event.returnValue=false;}"
  17. id="Textbox1" runat="server" Font-Names="Arial" Font-Size="9pt" MaxLength="10" Width="152px"></asp:textbox>
  18.  
  19.  
but i want to allow only a-z character and 0-9 number into the textbox. not allow any symbol
Mar 23 '10 #1
1 3173
jkmyoung
2,057 Expert 2GB
event.returnValue=false;
I thought you were supposed to return true, but I could be mistaken.

I suggest writing external functions to make the code cleaner. Then you could have those functions call other functions, like IsDigit(), IsLetter(), IsSymbol(), etc.

Also, you've posted in the wrong forum.
Mar 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nick | last post by:
In VS 2003 and VS 2005 beta 2 I am trying to write a simple program. It has a datagrid and a textbox along with a menubar. There is a command in the menu bar which is "Run Query" and has the...
16
by: Ramsin Savra | last post by:
Hi, What do you suggest to do if I want to do a search in TextBox ? I know that using RichTextBox, we could have Find method to search for a specific word or information but I was wonder if...
2
by: Dean L. Howen | last post by:
How to show special character (example anpha, beta, gama...) in TextBox/RichEditTextBox? Thanks
4
by: Peteroid | last post by:
I want to use a Textbox to allow the user to input a floating point number. In my case it will always be non-negative. Is there an easy way to do this, or possibly a link to some sample code that...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
2
by: Peter | last post by:
I hate using the mask edit conrol so I created these two function to format my phone numbers. Is there a way to consolidate these two functions into one? In this example say the textbox you...
2
Ajm113
by: Ajm113 | last post by:
I want to have a textbox that only allows Numbers, Periods, Spaces, and Minuses in it using C#. How is this accomplished? I already have the code set up like this: private void...
1
by: Luzuko | last post by:
I would like to know how can i restrict textbox input in VB.net using code instead of VB.net controls. e.g If i want a user to type numbers only in a textbox(ID number textbox), how can i make...
1
by: phpmel | last post by:
Hi all, I am have no idea at all how to do this. I want a textbox where the first character in the box is a 'M'.The user can see this but cannot change it. Now, i want to allow them to enter 5...
0
by: =?Utf-8?B?R3JlZw==?= | last post by:
I am new to C# and Web-Development, so I am not 100% sure how I should word my question. So, here goes my try. I've inherited a web application that was developed using C#. It appears to be an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.