---
title: "preg_match_all och email"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/57222-preg-match-all-och-email"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "nkrantz"
published: "2002-10-27T13:13:53.000Z"
updated: "2002-10-27T15:50:06.000Z"
replies: 4
views: 187
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/57222-preg-match-all-och-email"
---

# preg_match_all och email

## #1 — nkrantz, 2002-10-27T13:13Z

Hej!

Skall låta mina kunder skriva in en massa epostadresser i ett formulär, vill sedan ha alla validerade epostadresser in i en array. Problemet är som vanligt, pattern för email. Testade 

```php
preg_match_all ("/^[a-zA-Z0-9\-_.]+@[a-zA-Z0-9\-_.]+[.]{1}[a-zA-Z0-9]{2,3}$/i", $text, $ord);
```

men det funkade inte.. 

Någon som har ett tips?

/Niclas

Permalänk: https://www.webforum.nu/p/57222

## #2 — dectgap, 2002-10-27T13:22Z

```
/^[-a-zA-Z0-9_]+(\.[-a-zA-Z0-9_]+)*@[-a-zA-Z0-9_]+(\.[-a-zA-Z0-9_]+)*\.[a-zA-Z0-9]{2,3}$/i
```

Testa den istället.

Permalänk: https://www.webforum.nu/p/835894

## #3 — nkrantz, 2002-10-27T15:16Z

Nope.. den tar inte ut något...

Permalänk: https://www.webforum.nu/p/835968

## #4 — dectgap, 2002-10-27T15:37Z

```php
<?php

$email = "m.roslund@home.se";

if(preg_match_all("/^[-a-zA-Z0-9_]+(\.[-a-zA-Z0-9_]+)*@[-a-zA-Z0-9_]+(\.[-a-zA-Z0-9_]+)*\.[a-zA-Z0-9]{2,3}$/", $email, $matches)){
 $email = $matches[0][0];
}else{
 $email = "";
}

echo $email;
?>
```

Det fungerar.

Permalänk: https://www.webforum.nu/p/835975

## #5 — nkrantz, 2002-10-27T15:50Z

oki, tackar så mycket!

Permalänk: https://www.webforum.nu/p/835981

---

Tråden på webben: https://www.webforum.nu/amne/php/57222-preg-match-all-och-email
