473,473 Members | 4,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

validating a textbox

5 New Member
hi, i have to enter a value in a textbox that
should accept only alphabets and not digits
should accept only 4 characters
the first should be caps and the other must be small
--how can i do this .
Sep 12 '07 #1
5 2477
gurpreetintown
9 New Member
To restrict the textbox to these input conditions, impose these validations under the value change event of the textbox.
Sep 12 '07 #2
Nagendra Singh
4 New Member
U can use max length property of textbox to resrict number of characters.
use keypress event of text box and manipuate the capital letter.

if the e.KeyAscii > Keys.0 or e.KeyAscii <= Keys.0
don't allow
else
allow and change the capitals by adding + 26 to ascii of small letter
Sep 12 '07 #3
meena83
5 New Member
To restrict the textbox to these input conditions, impose these validations under the value change event of the textbox.


hi
but still i cant understand and i didnt find that valuechange event.
Sep 12 '07 #4
meena83
5 New Member
U can use max length property of textbox to resrict number of characters.
use keypress event of text box and manipuate the capital letter.

if the e.KeyAscii > Keys.0 or e.KeyAscii <= Keys.0
don't allow
else
allow and change the capitals by adding + 26 to ascii of small letter

hi
thanks for your reply. but still i m not clear.can you send me that coding part
Sep 12 '07 #5
Nagendra Singh
4 New Member
Expand|Select|Wrap|Line Numbers
  1.    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             if (e.KeyChar >= '0' && e.KeyChar <= '9')
  4.             {
  5.                 e.KeyChar = (char)Keys.None;
  6.             }
  7.  
  8.         }
  9.  
  10.         private void Form1_Load(object sender, EventArgs e)
  11.         {
  12.             textBox1.MaxLength = 4;         
  13.  
  14.         }
  15.  
  16.         private void textBox1_TextChanged(object sender, EventArgs e)
  17.         {
  18.             if (textBox1.Text.Length == 1)
  19.             {
  20.                 char[] c = textBox1.Text.ToCharArray();
  21.                 char[] c1 = c[0].ToString().ToUpper().ToCharArray();
  22.                 c[0] = c1[0];
  23.                 textBox1.Text = convertCharacterArrayToString(c);
  24.                 textBox1.SelectAll();
  25.             }
  26.  
  27.         }
  28.  
  29.         private string convertCharacterArrayToString(char[] c)
  30.         {
  31.             string str = "";
  32.             foreach (char character in c)
  33.             {
  34.                 str = str + character;
  35.             }
  36.             return str;
  37.         }
  38.  
Sep 12 '07 #6

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

Similar topics

6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
7
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
6
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.