Jump to content

sanitize/validate webaddress


Balderick
 Share

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?

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...