Results 1 to 10 of 10
  1. #1
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default TextField Validation

    Hi All

    how to set text field validation only numeric values?

    Help me

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Try something like this,

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

  3. #3
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Try something like this,

    Java 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
    Java 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..

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  5. #5
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    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..

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    6

    Default

    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

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. form validation
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 03-07-2008, 07:04 AM
  2. Swing Validation
    By ppayal in forum AWT / Swing
    Replies: 0
    Last Post: 02-09-2008, 09:00 AM
  3. Swing validation
    By ppayal in forum New To Java
    Replies: 0
    Last Post: 02-09-2008, 08:59 AM
  4. java validation?
    By lockmac in forum New To Java
    Replies: 3
    Last Post: 08-14-2007, 04:34 PM
  5. javascript validation
    By yuchuang in forum New To Java
    Replies: 5
    Last Post: 05-14-2007, 03:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •