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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.