Thursday 19 July 2012

Validation of URL (Website Address) and Email using PHP

//Validation of URL (Website Address) and Email using PHP
$post = $_POST;

// Validation of URL or Website Address
if (!isset($post['api_user']) || empty($post['api_user']))
 $errors[] = 'Enter Website name';  
else if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $post['website']))
 $errors[] = ''.$post['website'].' website name is not valid.';

//Validation of Email Address
if (!isset($post['paypal_address']) || empty($post['paypal_address']))
 $errors[] = 'Enter valid Paypal Email Address.';
else if (!(filter_var($post['paypal_address'], FILTER_VALIDATE_EMAIL)))
 $errors[] = 'Enter valid PayPal email address.';

No comments:

Post a Comment

Please post any queries and comments here.