Check URL Validity

Hello, I'm trying to figure out how to check the validity of a URL. I have wrote something, but it's not exactly what I want. Here is what I have:
     public boolean URLCheck(String checkme) {
          if((checkme.contains("http://") || checkme.contains("https://") ||
                    checkme.contains("ftp://")) && (checkme.contains(".edu") ||
                    checkme.contains(".com") || checkme.contains(".net") ||
                    checkme.contains(".org"))) {
               return true;
          else{
               output.setText("Bad URL.");
               return false;
     }This is obviously very flawed, it only checks the protocol and the end of the server address (com,org,net,etc...).
I would like to write a piece of code that could check if the URL is in this format, but I'm not sure where to begin.
< url > ::= < protocol >://< server_address >/< local_address >
< protocol > ::= http | https | ftp
< server_address > ::= < host >.< domain > | < host>.< domain >:< port >
< host > ::= < alphanumeric_character_string >
< domain > ::= < alphanumeric_character_string > |
               < alphanumeric_character_string >.< domain >
< port > ::= < numerical_string >
< local_address > ::= ~< login_name >/< location > | < location >
< location > ::= < null_string > | < file_name > |
                 < path >/ | < path >/< file_name >
< path > ::= < directory_name > | < directory_name >/< path >I'm not asking to have the code written for me, but I was wondering if someone could tell me how I could go about doing something like this.
Thank you in advance!

Thank you, here is what I tried:
     public void grabURLContents(String contents) throws Exception {
          try {
               URL inputFile = new URL(contents);
               BufferedReader in = new BufferedReader(
                              new InputStreamReader(
                              inputFile.openStream()));
               String inputLine, storage = "";
               while ((inputLine = in.readLine()) != null)
                   storage += inputLine +"\n";
               output.setText(storage);
               in.close();
          catch(Exception e) { output.setText("BAD URL: \n" + e); }
     }The only problem with this is: when I enter a url that obviously doesn't exist such as http://awdawfagasegr.com it still prints the html contents of my ISP's "Page not Found" page. Is there any way to prevent this?
Thank you for your help by the way. Sorry if I seem very ignorant, I am not familiar with Java's URL class.

Similar Messages

  • How to check URL validation in webdynpro?

    I get the error message in the webdynpro application of nw04 as followed:
    com.sap.tc.webdynpro.services.exceptions.InvalidUrlRuntimeException: Invalid URL=file:
    wdfd00184026a\ECM\CMIS\PlugFest
        at com.sap.tc.webdynpro.serverimpl.core.url.AbstractURLGenerator.checkURL(AbstractURLGenerator.java:699)
        at com.sap.tc.webdynpro.services.sal.url.core.URLGeneratorInternal.checkURL(URLGeneratorInternal.java:390)
    Does the system provide the function to checkURL so as to avoid the error?
    Thanks for help!

    Hi,
    You can create a simple type with built-in type as String. Then maintain a format as ##:##. But this will not restrict the user from entering junk value on the client side, a validation will be performed in the next request-response cycle.
    Regards,
    Satyajit.

  • Regex for URL Validation

    HI I am validating a field which takes a url as input from the user.So the url may contain http,https,ftp links or the user may specify the ip address.So can anyone please help me out to create a suitable regex for that.I just need to check the validness of link and not that it exists or not.

    here i have changed the regex as suggested by you but
    it returns true even for http://com.com@
    which is invalid.
    So it did not worked :-(It did not work, because you did not use it correct:
    public class Foo {
        private static boolean isValidUrl(String url) {
            return url.matches("(https?|ftp)://www\\.\\w+\\.\\w+");
        public static void main(String[] args) {
            String[] urls = {
                    "http://com.com@",
                    "http://www.com.com",
                    "http://www.com.nl",
                    "http://www.com.co.uk",
                    "http://www.com"
            for(String url : urls) {
                System.out.println(url+" valid? "+isValidUrl(url));
    }

  • Is there anyway we can check the validity of dump file in Unix system

    Hi,
    I have taken export of 2 tables which are huge in volume. one of the table seems to be successfully exported yet another one failed due to space scarcity. Since both the tables share a single dumpfile.
    I wanted to know.
    1. Can we use the same dumpfile to import the table which is successfull or it can not be used because the second table got error while exporting?
    2. Is there any way we can check the validity of dumpfile in unix plateform.
    Your reply is highly appreciated.

    784786 wrote:
    Hi,
    I have taken export of 2 tables which are huge in volume. one of the table seems to be successfully exported yet another one failed due to space scarcity. Since both the tables share a single dumpfile.
    I wanted to know.
    1. Can we use the same dumpfile to import the table which is successfull or it can not be used because the second table got error while exporting?No. It is better to take another backup of the same
    >
    2. Is there any way we can check the validity of dumpfile in unix plateform.
    Please check the export log backup. If it says that export terminated successfully, then the dump may be fine.

  • I Have iPad4 and using with Aricel Prepaid 3G SIM, How to check my VAlidity period and balance amount through iPad?. pls help me

    I Have iPad4 and using with Aricel Prepaid 3G SIM, How to check my VAlidity period and balance amount through iPad?. pls help me, M.Kumar, Chennai,
    <Email Edited By Host>

    There are 2 concepts attached to a bank balance. The balance as per your books of accounts and another is the balance maintained with the bank. I believe i need not explain these 2 concepts. These 2 balances can be obtained from Oracle system provided some of prerequsities are met with.
    Balance as per your books - This is nothing but the GL balance available. In order to obtain balances for each bank accounts, it is advised that each bank account should have a separate account code combination. This is achieved generally by having a separate natural account for each bank. The code combination is attached to the cahs account for each bank. By maintaining separate account code combination, the balance in each code combination can be obtained from GL (provided transactions are accounted and posted in GL). These balances represent the balance for each bank according to your books of accounts. You can create an FSG for this purpose and provide the same to the customer, so that they can run the same whenevr they want.
    Balance as per bank - This balance is maintained by oracle in 2 ways - either the bank balance can be manually entered for each bank account for each date (quite cumbersome). Else, while loading the bank statement, the bank balances are also loaded. There are various types of bank balances stored - value dated balance, available balance, float balance etc. Depending on the balances provided by bank along with the bank statement, the bank balance can be recorded in oracle system. After the bank statement is uploaded and balances stored, standard cash management reports are available to query for the bank account balances. In order to view daily movement, the bank statement should be loaded on daily basis.
    Hope this helps.
    Vinit

  • Unable to check certificate validity online. check...

    please help me on this... m not able to load anything
    my phone is n73-1
    Personal details removed by a moderator. We kindly ask you not to share your personal contact details publicly on this forum.

    Nokia Symbian/S60 wrote:
    Unable to check certificate validity online.
    As this could temper your security, before you change those settings (or at least after you changed them), please, have a look at a detailed explanation …

  • Check the validity of date

    hi..i'm creating a new user jsp page and in that i want to check whether the date entered by user as his/her date of birth is valid or not...i've taken three dropdown boxes to enter the date, month & year. how will i check the validity and concate three values and save it in database..thnx

    Validate it using java.util.Calendar which is set not to be lenient.
    Example: [http://balusc.blogspot.com/2007/09/calendarutil.html].
    Save it in DB using PreparedStatement#setDate().
    Example: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html].
    The field in DB must be a DATE, DATETIME, or TIMESTAMP.

  • How to check the validation of RegEx

    Hi,
    My application needs users to enter RegEx. My question is how I can check the validation of the RegEx that users enter. The Class RegExp does not seem to provide any methods to check the validation of the RegEx.
    Regards,
    Haibin

    You would need to hand roll your own validator, unless someone knows of one that is out there. Flex does not validate RegEx.
    If this post answers your question or helps, please mark it as such.

  • Check string validity with pattern

    hello,
    I want to check the validity of strings given by the user. The only characters authorized are : 'a' to 'z', 'A' to 'Z', '0' to '9', '.', '-', '_', '*', '@' and ' ' (space)
    i want to check this string with a pattern but it does not work.
    Somebody can help me for the pattern because the API javadoc is poor and i have a limited web access in my agency.
    Thanks
       String regex = "[a-zA-Z0-9.*-_@]";
       System.out.println(regex);
       boolean bol = Pattern.matches(regex, field);
       System.out.println(bol);
       ->> result always false for string field="Indy jones";

    try this:
    import java.sql.*;
    import java.io.*;
    import java.util.regex.*;
    import java.util.*;
    public class RegExTest2 {
    public static void main (String args[]) {
    Pattern pat = null;
    Matcher m = null;
    String patternToMatch = "^[a-zA-Z0-9\\.\\*\\-\\_@\\s]+$";
    String line1 = "IndianaJones";
    String line2 = "Indiana Jones";
    String line3 = "Indiana - Jones";
    String line4 = "Indiana&Jones";
    String line5 = "Indiana & Jones";
    String line6 = "  Indiana Jones  ";
    String line7 = "Indiana Jones =";
    pat = Pattern.compile(patternToMatch);
    System.out.println("Pattern to match = " + patternToMatch);
    boolean bol = Pattern.matches(patternToMatch, line1);  
    System.out.println("line1 : expected true and got " + bol);
    bol = Pattern.matches(patternToMatch, line2);  
    System.out.println("line2 : expected true and got " + bol);
    bol = Pattern.matches(patternToMatch, line3);  
    System.out.println("line3 : expected true and got " + bol);
    bol = Pattern.matches(patternToMatch, line4);  
    System.out.println("line4 : expected false and got " + bol);
    bol = Pattern.matches(patternToMatch, line5);  
    System.out.println("line5 : expected false and got " + bol);
    bol = Pattern.matches(patternToMatch, line6);  
    System.out.println("line6 : expected true and got " + bol);
    bol = Pattern.matches(patternToMatch, line7);  
    System.out.println("line7 : expected false and got " + bol);
      } // end main
    } //End Class RegExTest2

  • Check the validity of a SQL statement before execution

    Hi everyone,
    In an applet I have created, I am allowing the user to create a SQL statement which will be sent to a servlet that in turn issues the JDBC request for the SQL statement. My concern is that since my GUI lets the user create more or less any kind of SQL statement (including an illegal one) I need to verify if the user has created the correct SQL. How can this be achieved?
    To recapitulate and summarize, I need to know how I can check the validity of a SQL statement without actually executing it and handling the SQLException. FYI, I am using the mm-mysql driver.
    Thanks,
    Alan

    jschell is correct. Unless you're writing something like an ISQL tool you want to be very careful doing this.
    Having said that Mimer SQL have SQL validators that may do what you want http://developer.mimer.com/validator/index.htm
    They've also got the SQL Validator running as a web service that you can use. Theres example code here showing how to use it.
    http://sqlvalidator.mimer.com/index.html
    At the risk of being accused of selfpromotion you can check out the SQL Validator plugin for SQuirreL SQL CLient. This is a fully functional example of using the Mimer SQL Validation web service. http://squirrel-sql.sourceforge.net/
    Col

  • URL validation - regular expression

    Hello,
    I searched but didn´t find.
    I need a simple method: isValidUrl
    I tried "new URL(url)", getting error, but it allows a simple url with space... I tried too org.apache.validator but it brought me problems with related .jar...
    I got one validation for e-mail, that work very well using regex. Does anyone have URL validation using regular expression?
    Thanks.

    ^(http|https|ftp)\\://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\\-\\._\\?\\,\\'/\\\\\\+&%\\$#\\=~])*$
    It seems to work.Are you sure?

  • Ehancement for to check the validations in ME21n,ME22n,ME28,ME29n

    Hi experts...
    I have one requirement in Ehancement for to check the validations in ME21n,ME22n,ME28,ME29n...
    If the PO document date is after 31.12.2010 and vendor Group 1800 then check the Inco-terms with "SET" values whether the user entered value fals with in the "SET" value, if so then allow to save the PO else Else system should read the "SET" values and suggest user to select correct Inco terms.
    Example when user enter wrong Inco-Terms then system shoud give Error Message Please Select Inco-terms CPT or DAP or FCA..
    Can any body plz suggest me the user exit or Is it possible through the enhancement Framework...
    plz help me how to proceedd??
    Thanks & Regards,
    Veena.
    Moderator Message: Spec-dumping is not allowed.
    Edited by: kishan P on Jan 3, 2011 11:00 AM

    Hi Veena,
    To find a BADI for a given tcode follow the below steps.
    1. Go to the TCode.
    2. Menu Item System -> Status.
    3. Double click on the transaction Name (For ME21N double click on ME21N).
    4. Check the Package (e.g. ME)
    5. Go to TCode SE80
    6. In the drop down choose Package and type the Package Name (e.g. ME). Dont forget to Hit Enter or display.
    7. Object Name Enhancements -> Business Add-ins (Def.) (You will see all the BADI's available here ).
    In your case, you need BADI : ME_BAPI_PO_CUST.
    Go to SE19 to implement the BADI.
    If you put your conditions in Create Purchase Order(ME21N), you will not need to add them in Release PO(ME28N) since the conditions will be checked when PO is created.
    Regards,
    Jovito.

  • How to check the validity period of saprouter ?

    Dear all,
    As per sap note 1178684, we can check the validity period of the saprouter by executing "sapgenpse get_my_name -n validity"
    I am wondering how to run that command in as/400 ?
    Please advise. I am not familiar with as/400 OS.
    Thanks
    Regards,
    Kent

    Hi Kent,
    please proceed as described on the http://www.easymarketplace.de/snc-iseries-setup.php
    logon with sidadm (or sidofr):
    (depending on the user, that is running the SAPRouter)
    CD DIR('/usr/sap/saprouter')
    ADDLIBLE LIB(SAPROUTER)    ??? or whereever the stuff is ...
    RMVENVVAR ENVVAR('SECUDIR')
    ADDENVVAR ENVVAR('SECUDIR') VALUE('/usr/sap/saprouter')
    RMVENVVAR ENVVAR('SNC_LIB')
    ADDENVVAR ENVVAR('SNC_LIB') VALUE('/usr/sap/saprouter/sapcrypto')
    CALL PGM(SAPGENPSE) PARM('get_my_name')
    Regards
    Volker Gueldenpfennig, consolut international ag
    http://www.consolut.net - http://www.4soi.de - http://www.easymarketplace.de

  • UIWebView - how to check the validity of url

    How can I check that a webView has started loading a webpage?
    I notice that the webViewDidStartLoad method is not called if there is some problem in the target url.
    Is there any way to notify the user that the url provided does not exist?

    How is the date entered? As a string? If so, use java.text.DateFormat to parse the string. If the string represents a valid date, a date object will be returned.

  • Check for URL validity

    Ive done a quick google, and there are several methods by which to do this, but seem to tend towards http URLS.
    Essentially i just need to check if an ftp address is valid. i.e. There is a server there that responds in some fashion.
    Connection isnt necessary.
    Thanks

    JamesBarnes wrote:
    Essentially i just need to check if an ftp address is valid. i.e. There is a server there that responds in some fashion.
    Connection isnt necessary.Yes, it is. The only way to tell if there's an ftp server responding at some address and port is to connect to it.
    It's generally pointless to do these kinds of tests. If the URL class provides validation of the format, take what you can get there to see if it at least could be legal vs. is clearly totally bogus, but other than that, just try to connect. If you can, it's valid. If you can't, then either the server is not running or there's no network path to it. Diagnosing that is outside the scope of your application. (Unless you're writing a network services monitoring/management tool.)
    Even if you had some separate test and it succeeded, between the time that test passes and you try to connect, the server could shut down or a network problem could develop, so you cannot assume that just because the test passes, you can connect. Your connection and usage code will still have to handle communication failures.

Maybe you are looking for