Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE 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 23rd, 2003, 01:27 PM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to flaviostz
Default JText validation

I am writing a code to make a calculation. I use two JText inputs to make a division. However I would like to check if the JText is empty, or is equal to "" before make the calculation. Besides that I would like to check if it is equal zero.

What I really want to do is to check if the JText is not empty or has any space on it or if the value is different from 0. I want to use in the calculation only valid numbers.

Can you help me with that?

Thanks and regards,



Flávio de Souza
======================
[email protected]
ICQ: 78458203
======================
 
Old July 26th, 2003, 04:28 AM
Registered User
 
Join Date: Jul 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

What u can do is as follows:

First get the data from the JTextField:
say,
String value = text.getText();

if(value.length() > 0)
{
    try
    {
        int i = Integer.parseInt(value);
        // do further calculations
    }
    catch(ArthimeticException aE)
    {
         // throw appropriate Error msg
    }
}
else
{
    // throw appropriate Error msg
}



Regards,

Balaji





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation using Validation Framework kalyangvd Struts 1 January 2nd, 2008 06:53 AM
Validating Text in JText javanewbie05 Java GUI 3 June 23rd, 2005 08:35 AM
validation crmpicco Javascript How-To 2 February 4th, 2005 05:10 AM
JText flaviostz Java GUI 3 August 2nd, 2003 02:31 PM





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