I think the question title seems to explain eveything. I want to detect whether a string is in URL format or not using javascript.
Any help appreciated.
I think the question title seems to explain eveything. I want to detect whether a string is in URL format or not using javascript.
Any help appreciated.
Try this-
One for the future using the URL constructor and a basic try catch statement, it is supported in most modern browsers. Obviously no IE support...
If the URL is valid it will get parsed by the constructor and return true.
If the string is not a valid URL the constructor will chuck a syntax error that will get caught and return false.
You can use a regular expression for checking the string
Regular Expressions and Javascript
try something like this:
Debuggex Demo (Improved version which matches also 'localhost')
Try this code. This expression is more complete and takes into account IP address: