Jump to content

how to validate an url


keevitaja

Recommended Posts

Try filter_var() with the FILTER_VALIDATE_URL flag.

 

http://php.net/manual/en/function.filter-var.php

 

EDIT: Never mind, the documentation states

Validates value as URL (according to » http://www.faqs.org/rfcs/rfc2396), optionally with required components. Note that the function will only find ASCII URLs to be valid; internationalized domain names (containing non-ASCII characters) will fail.

 

I guess you would have to create your own function to do this. I can think of two options.

 

1. You can either create a regex that has a complete white-list of characters AND checks the pattern. This would be very elaborate and would probably require multiple patters.

 

2. If the additional characters you want to allow are only accented characters have a process that replaces the accented characters with their non-accented counterparts (and saves to a temp var) and then use filter_var() on that temp value. filter_var() would then validate all the other formatting/ properties of the URL. If validation passes you can then use the original value before the replacements were made.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.