Click here to Skip to main content
15,915,336 members
Home / Discussions / C#
   

C#

 
GeneralRe: Command Line Option in C# Pin
Calla19-Aug-09 0:23
Calla19-Aug-09 0:23 
QuestionCustom Control Events Pin
Matt Cavanagh18-Aug-09 22:30
Matt Cavanagh18-Aug-09 22:30 
AnswerRe: Custom Control Events Pin
dan!sh 18-Aug-09 22:54
professional dan!sh 18-Aug-09 22:54 
GeneralRe: Custom Control Events Pin
Matt Cavanagh18-Aug-09 22:57
Matt Cavanagh18-Aug-09 22:57 
GeneralRe: Custom Control Events Pin
dan!sh 18-Aug-09 23:17
professional dan!sh 18-Aug-09 23:17 
Questionvalidations for the controls that are dynamically created at runtime Pin
vasavi.p18-Aug-09 22:16
vasavi.p18-Aug-09 22:16 
AnswerRe: validations for the controls that are dynamically created at runtime Pin
OriginalGriff18-Aug-09 22:25
mveOriginalGriff18-Aug-09 22:25 
AnswerRe: validations for the controls that are dynamically created at runtime [modified] Pin
annathor18-Aug-09 22:46
annathor18-Aug-09 22:46 
maybe validate against a regex? ^\d+$


you could put it in the TextChange event handler method

eks.


private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Regex r=new Regex(@"^\d+$");
            Match m=r.Match(textBox1.text);

            if(!m.Success) MessageBox.Show("Wrong input format");
        }


or you could check the content of the textbox when it is submited, in the same fasion, using Regex and Match classes.

one idea is to make a class that inherits from the TextBox class, add a string attribute that can hold the regex expression, and use that class instead of the TextBox and store the regex in that variable, then you could just loop through all the controls when the user subits the data, an check it against the regex stored in that control, like this:

public class ExtTextBox:TextBox
{
 public string ValidationRegEx; //you shuld use get/set methods insted of setting the attribute as public, but I am lazy today.
}

....

//create the control
ExtTextBox newETB=new ExtTextBox();
...
...
newETB.ValidationRegex=@"^\d+$";
...
this.Controls.add(newETB);

//when user submits data
foreach(Control c in this.Controls)
{
 if(c is ExtTextBox)
 {
  ExtTextBox tmpC=(ExtTextBox)c;
  Regex r=new Regex(tmpC.ValidationRegex);
  Match m=r.Match(tmpc.Text);
  
  if(!m.Success)
  {
   //give feedback to user
  }
 }
}


modified on Wednesday, August 19, 2009 5:00 AM

QuestionWeb Application Security Pin
kKamel18-Aug-09 21:45
kKamel18-Aug-09 21:45 
AnswerRe: Web Application Security Pin
N a v a n e e t h18-Aug-09 22:08
N a v a n e e t h18-Aug-09 22:08 
GeneralRe: Web Application Security Pin
kKamel18-Aug-09 22:21
kKamel18-Aug-09 22:21 
Questiondon't allow to leave cell in datagridview Pin
mahdi198418-Aug-09 21:21
mahdi198418-Aug-09 21:21 
AnswerRe: don't allow to leave cell in datagridview [modified] Pin
Cracked-Down18-Aug-09 22:51
Cracked-Down18-Aug-09 22:51 
GeneralRe: don't allow to leave cell in datagridview Pin
mahdi198421-Aug-09 22:18
mahdi198421-Aug-09 22:18 
QuestionSmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 20:36
Le@rner18-Aug-09 20:36 
AnswerRe: SmsSendMessage still working when mobile have no balance. Pin
Christian Graus18-Aug-09 21:08
protectorChristian Graus18-Aug-09 21:08 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 21:40
Le@rner18-Aug-09 21:40 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Christian Graus18-Aug-09 23:23
protectorChristian Graus18-Aug-09 23:23 
GeneralRe: SmsSendMessage still working when mobile have no balance. Pin
Le@rner18-Aug-09 23:27
Le@rner18-Aug-09 23:27 
Questionconnecting to Telnet [modified] Pin
treuveni18-Aug-09 20:30
treuveni18-Aug-09 20:30 
AnswerRe: connecting to Telnet Pin
treuveni18-Aug-09 23:08
treuveni18-Aug-09 23:08 
Questiononline audio stream Pin
hossein khatoonabadi18-Aug-09 19:28
hossein khatoonabadi18-Aug-09 19:28 
QuestionGraphic Problem [modified] Pin
Reza Shojaee18-Aug-09 18:54
Reza Shojaee18-Aug-09 18:54 
AnswerRe: Graphic Problem Pin
Christian Graus18-Aug-09 19:29
protectorChristian Graus18-Aug-09 19:29 
Questionprocess words in c# Pin
prasadbuddhika18-Aug-09 18:40
prasadbuddhika18-Aug-09 18:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.