How can you detect a url in a textarea with JavaScript? With Facebook you can add a url and it will detect the address as soon as you finished pasting/typing it. How can this be done? I’ve done a lot of research on callback functions, etc. but am wondering how I can detect an actual url?
Share
If you are using jQuery the easiest way is with $.change().
Say you have a form field:
Now you can tie a change event to it, and at the same time find out if its a valid url:
Then you would have a function that checks for a url and returns a boolean value. Note, I took this from here
Disclaimer: I haven’t tested any of the javascript, but this should give you a good idea of how you could accomplish this.