Help needed about Javascript URL validation

Discussion in 'JavaScript' started by computerzworld, Oct 5, 2007.

  1. #1
    Hi friends. I am making URL validation with Javascript. The format I need for the URL is http://example.com without considering www in the URL. Please help me. Thanks in adavance.
     
    computerzworld, Oct 5, 2007 IP
  2. phd

    phd Active Member

    Messages:
    496
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #2
    try this one
    function checkURL(value) {
    var myregex = new RegExp("^(http:\/\/|https:\/\/|ftp:\/\/){1}([0-9A-Za-z]+\.)");
    
    if(myregex.test(value)) {
      return(true);
    }
    else {
      return(false);
    }
    
    Code (markup):
     
    phd, Oct 5, 2007 IP
  3. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    thnaks for the help..... i have tried like this...

    function checkURL()
    {

    var url = document.frm1.url.value;
    var myregex =new RegExp("^(http:\/\/){1}([0-9A-Za-z]+\.)");



    if(myregex.test(url))
    {
    document.write(url);
    return true;

    }
    else
    {
    alert("Error");
    return false;

    }
    }


    but it is considering www in the validation and i need url without www. So how to ignore www using this? plz help me... Thanks again.....
     
    computerzworld, Oct 5, 2007 IP