---
title: "Validate E-mail and URL in PHP"  
description: "Validate E-mail and URL in PHP"  
author: "Anonymous User"  
published: 2018-07-21  
updated: 2018-07-21  
canonical: https://www.mindstick.com/forum/34634/validate-e-mail-and-url-in-php  
category: "php"  
tags: ["php"]  
reading_time: 1 minute  

---

# Validate E-mail and URL in PHP

[Validate](https://www.mindstick.com/forum/1490/what-is-better-solution-for-validate-form-textboxs-value) E-mail and [URL](https://www.mindstick.com/forum/436/url-redirection) in [php](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) ?

## Replies

### Reply by Prakash nidhi Verma

Validate E-mail and URL in PHP :

Validate Name:

```
$name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  $nameErr = "Only letters and white space allowed";
}
```

Validate E-mail:

```
$email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format";
}
```

Validate URL:

```
$website = test_input($_POST["website"]); if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/

%=~_|]/i",$website)) {
  $websiteErr = "Invalid URL";
}
```


---

Original Source: https://www.mindstick.com/forum/34634/validate-e-mail-and-url-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
