---
title: "ereg - Bokstäver och mellanslag..."
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/99308-ereg-bokstäver-och-mellanslag"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Blårand"
published: "2004-03-12T13:54:02.000Z"
updated: "2004-03-12T21:36:06.000Z"
replies: 2
views: 246
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/99308-ereg-bokstäver-och-mellanslag"
---

# ereg - Bokstäver och mellanslag...

## #1 — Blårand, 2004-03-12T13:54Z

Hej!

Hur kompletterar jag följande kodnsutt, så att en sträng enbart kan innehålla bokstäver och mellanslag?

```
if (ereg("^[a-zA-ZåäöÅÄÖ]+$", $sokord)){
```

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

## #2 — Matte, 2004-03-12T21:04Z

```php
if (preg_match("/^[a-zåäöÅÄÖ ]+$/i", $sokord)){
```

 
Vill du att den som mellanslag även ska ta med saker som tab eller radbrytning (whitespace) så skriver du:

```php
if (preg_match("/^[a-zåäöÅÄÖ\\s]+$/i", $sokord)){
```

\[EDIT\]
Glömde bort att webforum strippar slashes i regexpar. Fixat.

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

## #3 — Blårand, 2004-03-12T21:36Z

Tack för hjälpen! :)

Mvh,
Blårand

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

---

Tråden på webben: https://www.webforum.nu/amne/php/99308-ereg-bokstäver-och-mellanslag
