java script : bookmark this page
posted by
mohamed basha
0
comment
إرسال بالبريد الإلكتروني
كتابة مدونة حول هذه المشاركة
المشاركة على X
المشاركة في Facebook
التسميات:
bookmark,
java code,
java script
c # : Number OnlyTextbox
First
- add two textbox ( txtType1, txtType2 )
- add three label ( label1, label2, label3 )
Second
- Right click on textType1 and choose properties
- move to Events and double click on KeyPress
Third
- add this code
//Using 2.0 Framework function TryParse
int isNumber = 0;
int.TryParse(e.KeyChar.ToString(), out isNumber);
if (isNumber == 0)
e.Handled = true;
Second
- Right click on textType2 and choose properties
- move to Events and double click on KeyPress
Third
- add this code
//Using Regular Expressions
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;
posted by
mohamed basha
0
comment
إرسال بالبريد الإلكتروني
كتابة مدونة حول هذه المشاركة
المشاركة على X
المشاركة في Facebook
التسميات:
c sharp,
c# code,
number only
C# Numbers Only in Textbox
I created a text box event handler to only allow my textbox to accept Numbers only. The Event handler works great and does not allow anything but numbers except when the form first loads and the character entered is non-numeric it then allows the first charcter to be entered can be non-numberic. If I enter a number then erase it it will not allow a non-numeric character.
I saw one example of this but the texbox had a underline in it but it did not have any code in it.
Here is my event handler right now
first way
C# Syntax
private void text1_TextChanged(object sender, EventArgs e)
{
text1.KeyPress += new KeyPressEventHandler(rtbQuantity_KeyPress);
}
private void text1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0') || (e.KeyChar > '9')) e.Handled = true;
}
sec way
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}
3rt way
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}
{
int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}
3rt way
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)
{
int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}
posted by
mohamed basha
0
comment
إرسال بالبريد الإلكتروني
كتابة مدونة حول هذه المشاركة
المشاركة على X
المشاركة في Facebook
التسميات:
c # Format,
c sharp,
c# code,
number only