Sam HobbsRank #107 · 20.5K reputationPosted Jan 11, 2012, 1:17 AM EST
0
Is this for a ASP application or a Windows Forms or WPF application? It would be better to not use the C# Language forum if any of the other forums corresponding to the UI applies.
I think the question whould be clarified. Do you want to validate the data as it is typed and not allow any invalid characters to be entered or do you want to validate the data after all the data is entered? Satyapriya' reply is for checking the data as it is entered and I think that Jignesh's and Ankit's reply is for after the data is entered.
I think there is also a templated textbox but as I say I do not know if the application is ASP or not or whatever.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 10, 2012, 6:57 AM EST
Try this...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;
}
Thanks
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 10, 2012, 9:33 PM EST
try this,
bool IsNumber(string text)
{
Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
return regex.IsMatch(text);
}
var isMatch = IsNumber(moblieno);
hope this help.
Ankit Shivnakr87 reputationPosted Jan 10, 2012, 9:53 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Jan 11, 2012, 1:17 AM EST
I think the question whould be clarified. Do you want to validate the data as it is typed and not allow any invalid characters to be entered or do you want to validate the data after all the data is entered? Satyapriya' reply is for checking the data as it is entered and I think that Jignesh's and Ankit's reply is for after the data is entered.
I think there is also a templated textbox but as I say I do not know if the application is ASP or not or whatever.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts