[thelist] javascript regexp help!
Mark Gallagher
mark at cyberfuddle.com
Fri Jul 5 00:05:01 CDT 2002
Erick Papadakis wrote:
> hi, i want to use regexp to find out if a URL entered
> is correct. i am trying the following code:
>
> myreg = new
> RegExp("/^(http|https|ftp):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/");
> if (myreg.test(url)) return true;
> else return false;
>
> what is wrong with this? sorry if the code above
> breaks and wraps on to four lines, but the first line
> is on one line so that is not the issue.
I'm guessing (since you're using regexps) that you already know this, so
if it seems I'm talking down to you - sorry.
But is your example just a simplified version, or did you really forget
to use the curly brackets {}?
myreg = new
RegExp("/^(http|https|ftp):\/\/((?:[a-zA-Z0-9_-]+\.?)+):?(\d*)/");
if (myreg.test(url)) {
return true;
} else {
return false;
}
(I'm not a big fan of JavaScript, so the above may not be *exact*. But
it's probably closer :-))
--
Mark Gallagher
http://cyberfuddle.com/infinitebabble/
More information about the thelist
mailing list