Earlier today I needed URL input validation (my form prompted for a URL, I needed to validate that what was provided was a syntactically valid URL). URL validation is actually rather complicated, but the following regular expression worked for me:
https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?
This one allows both http and https, supports an optional port, and allows paths and query strings too. Oh, it also works with both JavaScript (and can thus be used with
Leave a Reply