Asp.net text box (textbox) to determine whether the input is a number

Source: Internet
Author: User

CopyCode The Code is as follows: protected void txtqty_textchanged (Object sender, eventargs E)
{
Checkform ();
}
// Check whether the text information is valid. If the text information is valid, the calculation starts.
Protected void checkform ()
{
Try
{
If (! Isnumberic (txtqty. Text) & txtqty. Text! = "")
{
Checkbool = false;
Response. Write ("<SCRIPT> alert (the number can only be numbers. Please enter the number information. Thank you for your cooperation! ') </SCRIPT> ");
Txtqty. Text = "";
Txtqty. Focus ();
}
Else if (txtqty. Text! = "")
{
Qty = int. parse (txtqty. Text );
}
If (! Isnumberic (txtvat. Text) & txtvat. Text! = "")
{
Response. Write ("<SCRIPT> alert ('tax amount can only be a number. Please enter the number information. Thank you for your cooperation! ') </SCRIPT> ");
Checkbool = false;
Txtvat. Text = "";
Txtvat. Focus ();
}
Else if (txtvat. Text! = "")
{
VAT = double. parse (txtvat. Text );
}
If (! Isnumberic (txtunitprice. Text) & txtunitprice. Text! = "")
{
Response. Write ("<SCRIPT> alert ('price can only be a number. Please enter the number information. Thank you for your cooperation! ') </SCRIPT> ");
Checkbool = false;
Txtunitprice. Text = "";
Txtunitprice. Focus ();
}
Else if (txtunitprice. Text! = "")
{
Unitprice = double. parse (txtunitprice. Text );
}
If (checkbool = true)
{
If (VAT! = 0 & exvatamount! = 0)
{
Amountvat = exvatamount/(1-VAT/100 );
Txtamountvat. Text = amountvat. tostring ();
}
}
}
Catch (exception ex)
{
Console. writeline (ex. Message );
}
}
/// <Summary>
/// Name: isnumberic
/// Function: determines whether the input is a number.
/// Parameter: String otext: Source Text
/// Return value: bool true: false: No
/// </Summary>
Public bool isnumberic (string otext)
{
Try
{
// Conversion from string to double-precision value. If the string is converted to double, true is returned. Otherwise, false is returned.
Double var1 = convert. todouble (otext );
Return true;
}
Catch
{
Return false;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.