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));
}

Similar Messages

  • Regex for url pattern validation

    Hi,
    I am trying to find a regex for Url pattern validation that is not too restrictive.
    Please let me know, if anyone is using a pattern for their applications.
    Thanks
    Mayank Sharma

    are you talking about xml schema restriction?
    <xs:element name="url">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/_.]*)?)?" />
       </xs:restriction>
      </xs:simpleType>
    </xs:element>

  • Regex for URL Expression

    I am not a programmer, but I have to write a rule for CACHING the following URL that is being generated with "GET_QUERYSTRING".
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=198&my=247&request=gettile&zoomlevel=3
    As you can see, I would like to cache all the PNG map tiles, but I don't know how to come up with Regular Expression (regex) for the above URL.
    Thanks,

    are you talking about xml schema restriction?
    <xs:element name="url">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/_.]*)?)?" />
       </xs:restriction>
      </xs:simpleType>
    </xs:element>

  • RegEX for a valid mysql table name

    Hi all,
    i'm trying to figure out a regular expression for a mysql table so i can check if the string is a valid mysql table name.
    I don't know exactly the valid characters for a mysql table name.
    does any one have an Idea ?
    thnx

    You win the deal i don't know the characters :)
    Now come on. You know what DB you're using. Just google for some dox. Can't be that difficult.
    So what is the exception raised by mysql engine if
    not a valid name ?Depends on your DB and/or the JDBC implementation.
    >
    how can i catch it to prompt the user with a proper
    error message?I suppose by catching any exception risen when calling executeQuery() or the like and outputting its message.

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

  • Problem using regex for url

    Heres the problem im trying to match
    <b>Heres my text</b>
    and using this pattern
    Pattern rnpattern = Pattern.compile(".+rel-.+html.+id=.+>(.+)</a>.+");
    and I'm having to matches returned at all. Its actually pulling a full text file and running the pattern on a CharBuffer, but I dont think thats the issue. I have 2 other patterns being run the same way in the same file and theres no problem with them. I know the pattern is not optimized at all, Ive gone through about 15 different iterations of trying different combinations to try and get a match, and this is the last one I tried. the numbers in the url such as this one being 3533 change so that cant be static. And the text such as "Heres my text" changes and thats what I want to capture. If anyone could lend any assistance I would appreciate it.
    Chris N.

    http://www.foad.org/~abigail/Perl/url2.html

  • Regex for a URL

    How do I write a regex for the following URL. I am trying to write a regex rule in Oracle WebCache.
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=198&my=247&request=gettile&zoomlevel=3
    Thanks,

    I would start with a not so restrictiv expression.
    something like
    SQL> with testdata as (select '/myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=198&my=247&request=gettile&zoomlevel=3' urlstring from dual union all
      2                    select '/myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=200&my=300&request=gettile&zoomlevel=180' urlstring from dual union all
      3                    select '/myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&my=300&mx=200&request=gettile&zoomlevel=0' urlstring from dual union all
      4                    select '/myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map&mx=100&my=200&request=gettile' urlstring from dual union all
      5                    select 'somethingelse' urlstring from dual)
      6  select urlstring
      7  from testdata
      8  where regexp_like(urlstring,'^/myserver.domain.com:7779/mapviewer/mcserver[?]format=[PNG|SVG].+[mapcache=mvdemo.demo_map].+[request=gettile]');
    URLSTRING
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map
    &mx=198&my=247&request=gettile&zoomlevel=3
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map
    &mx=200&my=300&request=gettile&zoomlevel=180
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map
    &my=300&mx=200&request=gettile&zoomlevel=0
    /myserver.domain.com:7779/mapviewer/mcserver?format=PNG&mapcache=mvdemo.demo_map
    &mx=100&my=200&request=gettile
    SQL> In this example the url needs to include the mapcache, format and request parameter.
    Edited by: Sven W. on Oct 29, 2008 7:23 PM

  • 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?

  • W3C URL validation

    I have an XHTML (Transitional) page that includes absolute
    URLs to ColdFusion pages. These URLs include characters, such as
    &, that the W3C won't validate unless I change the characters
    to their ASCII equivalents. However, if I do this, then the URL
    doesn't work.
    Is there a way to validate ColdFusion URLs in W3C's
    validator?
    Thank you.

    Why won't something like this work?
    <a
    href="page.cfm?cat=#rsTest.cat#&amp;subcat=#rsTest.cat#">#rsTest.item#</a>
    The &amp; replaces the &
    Ken Ford
    Adobe Community Expert - Dreamweaver
    Fordwebs, LLC
    http://www.fordwebs.com
    "Urmo5" <[email protected]> wrote in message
    news:fv786p$cgm$[email protected]..
    > I'm not a ColdFusion developer - so I'm not sure why our
    URLs have these
    > characters in them. I'll ask one of our developers.
    >
    > No, I wasn't aware that there is a different escaping
    ASCII scheme for
    > URLs.
    > Is there a list of these available somewhere?
    >
    > Thanks for the response.
    >

  • How to remove bullets and spacing for url links in the Related Links iview?

    I tried to look for a property that I can edit the look-n-feel of the url links in the Related Link iView using "Theme Editor".
    All I need is to remove the bullets and increase some vertical spacing between the links.
    Currently, it looks like this:
    URL iView A
    URL Iview B
    I go through the whole section of Related Links properties, none of them seems to do what I want.
    Here are the list of properties in Related Link section (of Navigation Panel):
    Link Color
    Text Decoration of Link
    Hover Color
    Text Decoration of Hovered Link
    Initially, I thought "Text Decoration of Link" should be the right property I should look at. But there are a drop-down with 5 options: None, Underline, Blinking, Overline and Line-Through, which really can't achieve what I want.
    Thanks for advice.
    Kent
    Post with Diagram Illustration:
    <a href="http://sapnetweaverforum.blogspot.com/2006/11/how-to-remove-bullets-and-spacing-for.html">How to remove bullets and spacing for url links in the Related Links iview?</a>
    Message was edited by: Kent C.

    Hi, Kai.
    I checked the Related iView properties (URL Template), I don't see what layoutset it is really using. I am not sure, is that a layout set apply to the Related Link Iview?
    For the regular KM iView, I will see what Layout Set I want to apply, then I can go and change the properties (of layout coontroller, collection renderer & resource renderer)you mentioned. But for this Related Link iView, I really don't know. I guess it may be in the code itself.
    If there is a layout set for Related Link iView (or the place to apply layout set to it), can you point to me which one is that? (I did a search through the layout set names, I only find the AppQuicklinkExplorer (I used this for Dynamic Nav. Link iView before), if I can aply this layout set to Related Link iView, my problem will be solved.)
    Thanks for help.
    Kent

  • Object Services Attachements for URL Links

    Hi Guru,
      I have to create interface for Object Services Attachments for URL links.
    Scenario is
    Drad Table:
    DOKOB = PTRV_HEAD
    DOKNR = 0000000000000001000000000098
    objky = 0050000088\
    Draw Table:
    doknr = 0000000000000001000000000098
    filep: rgenbust:/DCTM370097578000AD0C
    Create object service url attachment with:
    http://rdgvmws10:8080/WebAccess/TEServlet.ser?docbase=rgenbust&sapLinkId=
    appended to FILEP after the /
    to make a link of:
    http://rdgvmws10:8080/WebAccess/TEServlet.ser?docbase=rgenbust&sapLinkId= DCTM370097578000AD0C
    I unable solve this issue can any help with the source code.
    I need to create program with scratch. Can any body tell me how to start the program. First which table i need to read. How to retrieve URL append to FILEP field. I would appreciate if any body help.
    Thanks
    Ashraf

    Hello,
    See hyper-links below:
    [How-To: Offline approval - Logon link does not work|http://wiki.sdn.sap.com/wiki/display/SRM/Offlineapproval-Logonlinkdoesnot+work]
    [KBA 1511180 - The hyperlink in the offline approval email is incorrect|https://service.sap.com/sap/support/notes/1511180]
    Regards.
    Laurent.

  • Java.io.FileNotFoundException: Response: '404: Not Found' for url:

    Hello,
    I am in the processing porting a J2EE based application deployed originally in OC4J to WLS. I am not changing anything as far as J2EE/Web configuration files such as web.xml. Whenever I hit the URL of the application, I am getting the below exception.
    What does usually "java.io.FileNotFoundException: Response: '404: Not Found' for url...." indicate?
    If you could please give me some pointers to narrow down the places to look, I would appreciate it.
    Thanks,
    Mustafa
    java.io.FileNotFoundException: Response: '404: Not Found' for url: 'http://cayc
    001geo1:7001/IUS_Editor/mapservlet'
    at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnectionjava:487)
    at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConection.java:37)
    at oracle.lbs.mapclient.MapViewer.getXMLResponse(MapViewer.java:6013)
    at oracle.lbs.mapclient.MapViewer.getDataSources(MapViewer.java:629)
    at gov.census.geo.maftiger.interactiveupdate.navigation.mapservlet.ISGegraphyController.getMapviewerDS(ISGeographyController.java:730)
    at gov.census.geo.maftiger.interactiveupdate.navigation.mapservlet.ISGegraphyController.doPost(ISGeographyController.java:161)
    at gov.census.geo.maftiger.interactiveupdate.navigation.mapservlet.ISGegraphyController.doGet(ISGeographyController.java:73)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:821)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.ru(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurtyHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.ja
    a:300)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.ja
    a:184)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActi

    Hello,
    I was able to sort out this issue. I was comparing the web.xml and found out that the servlet-mapping was missing.
    Thanks,
    Mustafa

  • Java.io.IOException: Server returned HTTP response code: 405 for URL

    I'm trying write to a file using a combination of CGI and Java. I am following this website:
    http://www.webdeveloper.com/java/java_jj_read_write.html
    However, when I try to write out to the file, I keep getting the error in the title: HTTP response code: 405 for URL: .....
    I was wondering if anyone knew what this mean? I searched the forum and found a post from 2 years ago that was exactly the same problem I was having, only thing is that there were no responses to it. Hopefully I'll have a bit more luck.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

  • IOException  :server returned http response code:505 for url url

    hi,
    my program creates IOException server returned http response code:505 for url <some url>
    I close the i/p stream.I dont know ,where is the problem.plz let me know.Thanks in advance.
    Here is the code:
    public class CallApplicationURL
    private static final String className = "[CallApplicationURL] ";
    private MailAlert ma = new MailAlert();
    public String callURL(String purl, RequestObject ro, Debug log)
         URL url = null;
         String URLResponse = "No response from Provider";
         ProxySetter ps = new ProxySetter();
         try
              ps.setProxy(ro, log);
              url = new URL (purl);
         catch (Exception e)
         URLResponse = className+"Exception while URL assignment \n"+purl+"\n, Exception is "+e;
         return (URLResponse);
         try
         HttpURLConnection h = (HttpURLConnection) url.openConnection();
         h.connect();
         BufferedReader br = new BufferedReader( new InputStreamReader( h.getInputStream() ) );
         URLResponse = br.readLine();
         br.close();
         catch (Exception e)
              URLResponse = className+"Exception while calling URL "+purl+", Exception is "+e;
         return (URLResponse);
         return (URLResponse);
    }

    http response 505: http://libraries.ucsd.edu/about/tools/http-response-codes.html
    This would indicate nothing is wrong with your applet but with your http server (not supporting http 1.1??)
    A full trace might help:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    When you catch the exception you should print the stacktrace: (e.printStackTrace()).

  • Server returned HTTP response code: 503 for URL

    I was deploy my webcenter application and was working fine, but I updated my Webcenter Framework plugin in Jdeveloper to version 11.1.2.0.091030.1847 and now when I try deploy my application error 503 occurr:
    [05:06:55 PM] Weblogic Server Exception: weblogic.deploy.api.internal.utils.DeployerHelperException: The source 'C:\Users\nmaia\AppData\Local\Temp\app8.ear' for the application 'app8#V2.0' could not be loaded to the server 'http://it7-srv-lnx-wcenter:7002/bea_wls_deployment_internal/DeploymentService'.
    Server returned HTTP response code: 503 for URL: http://it7-srv-lnx-wcenter:7002/bea_wls_deployment_internal/DeploymentService
    [05:06:55 PM] See server logs or server console for more details.
    [05:06:55 PM] weblogic.deploy.api.spi.exceptions.ServerConnectionException: [J2EE Deployment SPI:260041]Unable to upload 'F:\Desenvolvimento\JDev\Application8\deploy\app8.ear' to 't3://it7-srv-lnx-wcenter:7002'
    [05:06:55 PM] #### Deployment incomplete. ####
    [05:06:55 PM] Remote deployment failed (oracle.jdevimpl.deploy.common.Jsr88RemoteDeployer)
    My Weblogic is version 11g(10.3), can anyone help me?
    Thanks,

    To solve my problemn I do these steps:
    - Uninstall jdeveloper;
    - Delete jdeveloper folder;
    - Install Jdeveloper, version 11.1.1.2;
    - Downloaded the plugin to Webcenter: http://download.oracle.com/otn/java/jdeveloper/1112/extensions/oracle.webcenter.framework_bundle.zip
    - Remove my proxy from Jdev ( Tools -> Preferences -> Web Browser and Proxy)
    And works fine.
    Thks anyway.
    []'s

Maybe you are looking for

  • Using iTunes on an external drive..

    So I know how to put my libary on an external drive and pull music from that. My problem is this: my external drive is connected to my airport extreme. I have two laptops that my fiance and I use and we both want to pull music off it. It works, but w

  • HR ABAP:  table/infotype relationships

    Hi. I'm experienced in doing ABAP programming for all the rest of the modules, but with ABAP HR, I am new and doing one for the first time.  I need your help regarding how to find tables/infotypes and relationships to each other. Specific work exampl

  • When SDDM x64 says "Cannot find a J2SE SDK installed at ..."  what is it actually looking for?

    First of all,please forgive me if this question has been answered before, but search facilities in this new forum are even more rubbish than the old one, which is an achievement I wouldn't have thought possible. Anyhoo. I have downloaded the 64-bit v

  • German Language packed for Photoshop CS6

    I'm a first time user . We purchase Photoshop CS6 for our comnpany here in China. The Version is English / China so I can discuss we my china collegues.  But my mother tougue is german and i have some problems to understand the english technicall ter

  • Log processing missing after 10.1.3 install.

    After I installed 10.1.3 my "log processing" was missing.  Another computer had retained it after the upgrade. What can I do now?