Jump to content
Sign in to follow this  
Balderick

sanitize/validate webaddress

Recommended Posts

Hi all,

I have a problem for sanitizing / validating a web address input.

My personal favor is doing it with regex.

I made a simple example with preg_replace

    <?php 
	if (!empty($_POST['wbddrss']) )   {
			
	$wbddrss = $_POST['wbddrss']; 	
	$wbddrss = trim($wbddrss);
	var_dump($wbddrss);
	$validate = preg_replace('/<>/' , '', $wbddrss);
	var_dump($validate);
    } ?>

 

But I would like to replace all chars that do not meet what is allowed.

I guess the best solution would be to replace everything with a caret to negate. But it seems I cant find the right delimiters.

This is the range of characters I would like to allow:

A-Za-z0-9+&@#/%?=~_|!:,.;\(\)

how is this done in a preg_replace function?

 

 

 

Share this post


Link to post
Share on other sites

I guess I solved this by using amongst others str_replace for the unwished input and I found a regex online that replaced all except the %

 $url = preg_replace("/([^a-zA-Z0-9+&@#?=~_|!:,.;]+)/","",$url);

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...