Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2008, 08:29 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
TextField Validation
Hi All

how to set text field validation only numeric values?

Help me
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-28-2008, 08:53 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,065
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Try something like this,

Code:
String temp = txtField.getText(); try { int val = Integer.parseInt(temp); } catch(NumberFormatException e) { System.out.println("Invalid"); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-28-2008, 11:12 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Try something like this,

Code:
String temp = txtField.getText(); try { int val = Integer.parseInt(temp); } catch(NumberFormatException e) { System.out.println("Invalid"); }
Thxs sir

Through this i can validate for only interger. Sir i want to validate for IP formate
Code:
0.0.0.0
I use float but it only take "0.0" formate.So how can i set the validation for "0.0.0.0" this formate..
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-28-2008, 11:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,065
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
In that sense try to make a pattern and validate. Or in simple way, validate each number separating with the dot. Since you are talking about IPs, best thing would be patterns.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-28-2008, 11:22 AM
Mir Mir is offline
Senior Member
 
Join Date: Mar 2008
Posts: 447
Mir is on a distinguished road
Quote:
Originally Posted by Eranga View Post
In that sense try to make a pattern and validate. Or in simple way, validate each number separating with the dot. Since you are talking about IPs, best thing would be patterns.
ok Can you give me some idia of patterns code..
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-28-2008, 11:24 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,065
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Refer regex documentation.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-28-2008, 06:37 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 282
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
One more way is u can trim the IP address for "." and then do a Integer.parseInt() for each part.
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-29-2008, 06:34 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,065
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Niveditha View Post
One more way is u can trim the IP address for "." and then do a Integer.parseInt() for each part.
Yes, this is the easiest way if you don't know how to deal with patterns.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-29-2008, 07:22 AM
Senior Member
 
Join Date: Jun 2008
Posts: 220
Fubarable is on a distinguished road
JFormattedTextField
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 06-29-2008, 07:28 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,065
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I don't think he want to read that a long material.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
(Close on September 4, 2008)

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
form validation abhiN New To Java 0 03-07-2008 08:04 AM
Swing Validation ppayal AWT / Swing 0 02-09-2008 10:00 AM
Swing validation ppayal New To Java 0 02-09-2008 09:59 AM
java validation? lockmac New To Java 3 08-14-2007 05:34 PM
javascript validation yuchuang New To Java 5 05-14-2007 04:38 PM


All times are GMT +3. The time now is 08:16 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org