 |
|
| I posted a some time ago now which was a Javascript function that was suppose to validate an url. It works ok but the function is very long and didn't cover all cases. For example the url must have "www" and the address can not start with "https". So a much better way is to use a regular expression instead to match an input string with. If the function returns true the string is a valid url and else its not. function urlCheck(str) { var v = new RegExp(); v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$"); if (!v.test(str)) { return false; } return true; } |
|  |
| | Comments:
|
| | Comment posted 2009-03-31 22:32:53 by sFBGDVBDVG
shmnhmnh((ftp|(http(s)?))://)?(\.?([a-z0-9-]+))+\.[a-z]{2,6}(:[0-9]{1, 5})?(/[a-zA-Z0-9.,;\?|\'+&%\$#=~_-]+)*$!i',
|
|
| | Comment posted 2009-06-01 08:50:40 by
If you’ve ever programmed in Perl, or have had in your hands a UNIX system, then maybe you are pretty familiar with what regular expressions are. If you think that JavaScript is not well suited for your client-side Web programming needs, only useful to open pop-ups and other fancy windowing-related stuff, you don’t know the whole story. JavaScript includes full support for Perl-style regular expressions, and it's extremely useful for string matching processes, as I will try to demonstrate in the following lines.I’ll start out explaining what, exactly, regular expressions are, and what they can do for you when used in JavaScript. Finally, I’ll show some practical examples, giving a quick taste of how powerful they can be when they are utilized for client-side data validation. Just keep reading!
|
|
| | Comment posted 2009-06-01 13:17:10 by
really very informative post. thanks for sharing. i think it will be helpful for every reader.
|
|
| | Comment posted 2009-06-01 13:25:08 by
Well, where are the powerful and extremely useful explanations and examples? I am very eager to see them.
I don't really know what you want to say with this comment. The url check above does what I want it to do. And just for your information I am aware of other languages' capability of regular expressions. See for example this post which describes a regular expression which validates en email address ->
But if you just want to share your knowledge you are more than welcome
|
|
| | Comment posted 2009-06-02 08:06:56 by
Really there are a couple of issues that you need to get past before you can make sure that your Javascript pop ups can run properly on anybody else's computer.
|
|
| | Comment posted 2009-06-03 07:14:47 by
We might wish to consider an alternative to java script menus, which can still provide some pretty impressive effects and allows search engines to read and follow the text links.
|
|
| | Comment posted 2009-07-08 06:48:21 by
It' s really very useful post. java is also a platform independent language that's the imp. It really helpful for who found knowledge.
|
|
| | Comment posted 2009-07-20 16:57:10 by Tom
Does this page parse links?
|
|
| | Comment posted 2009-08-06 06:14:47 by
Nice - except the url checker you are using for this comment field does not allow non-www. . Have you considered uploading your routines to Hotscripts?
|
|
| | Comment posted 2009-10-19 12:08:42 by tarun sachdeva
check it again.. it works wrongly for many cases.
it validates many invalid URL's.
|
|
| | Comment posted 2009-10-19 12:24:48 by
Ok tarun, If you have many examples of invalid URLs - show them to me or at least one???
If there are such which does not interfere with the specified requirements as written in the post I am happy to look at them and modify the script.
Please also understand that this script is not checking if an URL actually exists or not, it only checks the syntax.
// Niklas
|
|
| | Comment posted 2009-10-31 12:15:02 by
Very informative post really. I am very grateful to you.
|
|
| | Comment posted 2010-05-06 21:09:33 by
hey! thanks for the share! i used this in my site! thaks a lot!
|
|