winforms text box that accepts max 5 characters and the first letter must be the alphabet 'a'

Posted by Kishore under C# on 3/14/2010 | Views : 2480 | Status : [Member] | Replies : 5
i want to create a text box that accepts max 5 characters and the first letter must be the alphabet 'a'




Responses

Posted by: Abhi2434 on: 3/14/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Why dont you use Regular Expression ?

Use

"[Aa]\w{0,4}"


Check this on Keypress/textchanged or any event of a textbox.


www.abhisheksur.com

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/14/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Abi can you give him a full detail example , because i suspect he does not know how to do what you said

Thank you for posting at Dotnetfunda
[Administrator]

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 3/14/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
I think you are right.


Regex expression = new Regex("[Aa]\w{0,4}");
return expression.Match(Textbox1.Text);


I think something like this is he require.

I am still waiting for the user to get back with this. :)
I dont know if the user already found the solution or not, and what event the user is handling etc.

www.abhisheksur.com

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 3/15/2010 [Member] Starter

Up
0
Down
Hi,
use the following code to check the Length and character in winforms based on your condition..

private void button1_Click(object sender, EventArgs e)
{
string txtvalue = textBox1.Text;
if (txtvalue.Length < 5 || txtvalue.Length >5)
{
MessageBox.Show("Text Lenght should be 5 characters");



}
if (!char .IsLetter (txtvalue [0]))
{
MessageBox.Show("First Letter should be character");
}

}

Syed Shakeer Hussain

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 3/16/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
This is very manual..
Though it works, but its not Smart coding .. :D :D

www.abhisheksur.com

Kishore, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response