Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:24:56+00:00 2026-06-08T21:24:56+00:00

I need to validate if string entered in TextEdit is a web address eg.

  • 0

I need to validate if string entered in TextEdit is a web address eg. “www.stackoverflow.com” or an ip address eg. “64.34.119.12”. I have tried this two methods without success. I have private class variable named ip.

Method 1:

public boolean isAdress(){

        boolean isaddr = true;
        try
        {
            ip = new NetTask().execute(""+textEdit1.getText()).get();
        }
        catch (Exception ex)
        {
            isaddr = false;
        }
        return isaddr;
    }

Method 2 is the one were I check string before sending it to NetTask.

public boolean isAdress(){
        String adress = textEdit1.getText().toString();
        boolean isaddr = true;
        if (adress.length() > 0) {
            String[] nums = adress.split(".");
            if (nums.length == 4) {
                for (String str : nums) {
                    int i = Integer.parseInt(str);
                    if ((i < 0) || (i > 255)) {
                        isaddr = false;
                    }
                }
            } 
        }
        return isaddr;
    }

this second method also doesn’t wotk, but even if it did, it wouldn’t be able to validate web adress.

So it there any way I can validate string for both of this cases?

EDIT:
After reading about regex I tried this method also:

private String regex = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";

public boolean isAdress(){
        String adress = textEdit1.getText().toString();
        try {
            Pattern patt = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
            Matcher matcher = patt.matcher(adress);
            return matcher.matches();
        } catch (RuntimeException e) {
        return false;
    }           
    }

but it seems to return false all the time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:24:57+00:00Added an answer on June 8, 2026 at 9:24 pm

    Short answer: Try using regex!

    EDIT:

    if(textEdit1.getText().matches(REGEX_URL)) {
        //DO URL THINGS
    }
    
    if(textEdit1.getText().matches(REGEX_IPADDRES)) {
        //DO IP THINGS
    }
    

    If you google you can find the correct REGEX strings for IP addresses and urls…

    NOTE:
    A regex for urls can be different for what you want, do you only want http:// https:// or all valid urls (like market://)…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really got stuck on this simple regex. Need it to validate a string, that
i need to validate this type of string 0415256987, 0452 654 987, 0411 236589,
my application takes in a string like this 2002-10-15 10:55:01.000000. I need to validate
I need to validate the just the format of the entered string for Latitude
I need to validate input to my application. The input is a formatted string
I need a regex or a function in PHP that will validate a string
I need to validate file name with following pattern.... File name(string) should not be
I need to validate that the text entered in a qlineedit has the form
I have a calculation application which I need to validate the fields to check
Possible Duplicate: Regular expression to match hostname or IP Address? I need to validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.