Click here to Skip to main content
14,825,882 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have to Enter in to an Sector text, it has to come like this /AAA/AAA/AAA/AAA/AAA/,ITS ALREADY THE TEXT HAS SET AS WHEN WE HAD ENTERED IN TO THAT TEXT IT WILL SHOWS LIKE THIS __/__/__/__/__

PLS HELP ME SIR?
Posted
Updated 5-Feb-12 19:26pm
v3
Comments
Rajeev Jayaram 1-Feb-12 1:44am
   
What do you mean? You don't want '/' as the input?

Add a KeyPress event handler on the TextBox.
Then put in this code into the textbox. This will allow only alphabets or /.

C#
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!Regex.IsMatch(textbox.Text, @"[a-zA-Z/]"))
    {
        e.Handled = true;
    }
}
   
C#
<pre>Regex rx = new Regex(@"^[a-zA-Z]+$");

if(!rx.IsMatch(TextBox1.Text)){

//code for handling error

}



Also, refer to this article for an understanding about regular expressions.

"http://www.codeproject.com/KB/cs/Regular_Expressions.aspx"
   
v4
Here is an excellent CP article for your reference,
Enhanced Textbox Control[^]

Some links that would help,
http://forums.asp.net/t/1272776.aspx/1[^]
SOF[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900