Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2004, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Validation question

I have the following method, IN MY WINDOWS FORM, that I am trying to call in another part of my code:

private bool IsNumeric( string TextValue )
{
    bool IsNumeric = false;
    try
    {
        Convert.ToInt32( TextValue );
        IsNumeric = true;
    }
    catch ( Exception e ) { }
    return IsNumeric;
}

Here is where I am trying to make a call to the method above to check and see if what the user is entering in the textbox is a NUMERIC value. If an ALPHA character is contained in the textbox then launch the message box that I have listed below:

private void Load_Datagrid()
{
    Cursor.Current = Cursors.WaitCursor;

//If the CLIENTID field is left blank or a NON-NUMERIC value is entered then pop-up this message box.
    if (txtClientID.Text.ToString().Length < 1 || IsNumeric(txtClientID.Text.ToString()))
    {
    System.Windows.Forms.MessageBox.Show(this,"A NUMERIC Client ID must be entered."); //\n\n\t", System.Windows.Forms.MessageBoxButtons.OK,System.W indows.Forms.MessageBoxIcon.Warning);
          return;
    }

Any HELP or DIRECTION would be appreciated. I am just getting an exception error and NOT my message box.

Thanks.
 
Old July 16th, 2004, 04:47 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think you have forgotten '!'
if (txtClientID.Text.ToString().Length < 1 || !IsNumeric(txtClientID.Text.ToString()))

-----------------------------------
Mahdi
 
Old July 19th, 2004, 07:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Mahdi,

That was it! Thank you so much. I appreciate your time and help in looking at this.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation in C++ code_lover C++ Programming 3 July 23rd, 2008 01:26 AM
Validation using Validation Framework kalyangvd Struts 1 January 2nd, 2008 06:53 AM
validation dhaval229 ASP.NET 1.0 and 1.1 Professional 2 February 14th, 2006 02:10 PM
Validation Question mar0364 VBScript 8 July 26th, 2004 02:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.