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

  • Home
  • SEARCH
  • 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 8478929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:53:04+00:00 2026-06-10T18:53:04+00:00

I would like javascript detect the source of the image and take action regarding

  • 0

I would like javascript detect the source of the image and take action regarding it is full URL or not with REGEX

Example Code:

var source = 'http://test.com/';
if( [if var source starting with http:// ] ){ // Regex conditional
    // do something
}else{
    // // something
}

How to do that with Javascript regex?

Thank you…

  • 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-10T18:53:05+00:00Added an answer on June 10, 2026 at 6:53 pm

    Here you go if you are adamant on Regex:

    ^https?:\/\/.*$
    

    Javascript code to test here:

      var re = /^https?:\/\/.*$/;
      var sourcestring = "source string to match with pattern";
      var matches = re.exec(sourcestring);
      for (var i=0; i<matches.length; i++) {
        alert("matches["+i+"] = " + matches[i]);
      }
    

    For your code:

    var source = 'http://test.com/';
    var pattern = /^https?:\/\/.*$/;
    if(null != pattern.exec(source))
    { 
        // Regex conditional
        // do something
    }
    else
    {
        // // something
    }
    

    But please note that this ONLY checks the first part of the URL, which may not necessarily mean that the rest of the string conforms to an URL. For e.g., your source string can be something like “http://^&#*@%.IAmABadUrl.com” which is not a valid URL if sent unencoded.
    More about whats allowed in an URL on the IETF website:

    Thus, only alphanumerics, the special characters “$-_.+!*'(),”, and
    reserved characters used for their reserved purposes may be used
    unencoded within a URL.

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

Sidebar

Related Questions

I have some clients who are not English speaking. They would like the JavaScript
I would like to change a line of my javascript code based on whether
Is there anyway to detect if a JavaScript object is a regex? For example,
i would like make a script that detect if the page is full loading
I would like a JavaScript function to have optional arguments which I set a
Hovering the mouse over an element flips it. I would like a JavaScript function
I would like to call JavaScript function many time . I have tried like
I would like to send a javascript array to be processed by a method
I would like to embed a javascript engine into an ANSI C application. In
I would like to add a Javascript at the end of some ajax content,

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.