From: "Tanel Tammik" on
How to check with regular expression (preg) if string has:

1. only letters
2. only letters and spaces

Br
Tanel


From: Adam Richardson on
On Tue, Jun 1, 2010 at 11:19 AM, Tanel Tammik <keevitaja(a)gmail.com> wrote:

> How to check with regular expression (preg) if string has:
>
> 1. only letters
> 2. only letters and spaces
>
> Br
> Tanel
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
$re1 = '/^[a-zA-Z]+$/';
$re2 = '/^[a-zA-Z ]+$/';

Adam

--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com
From: Ashley Sheridan on
On Tue, 2010-06-01 at 18:19 +0300, Tanel Tammik wrote:

> How to check with regular expression (preg) if string has:
>
> 1. only letters
> 2. only letters and spaces
>
> Br
> Tanel
>
>
>


Use preg_match() to find an expression within a string. You can use
something like this to grab check if a string contains only letters or
numbers:

if(preg_match('/^[a-zA-Z0-9]+$/'), $string)
{

}

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Richard Quadling on
$re1 = '/^[a-z]++$/i';
$re2 = '/^[a-z ]++$/i';



--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
From: Ashley Sheridan on
On Tue, 2010-06-01 at 16:31 +0100, Richard Quadling wrote:

> $re1 = '/^[a-z]++$/i';
> $re2 = '/^[a-z ]++$/i';
>
>
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>


Why the double ++ in the expressions there? Surely one + would match the
1 or more characters that you need and the second one would just be
surplus?

Thanks,
Ash
http://www.ashleysheridan.co.uk


 |  Next  |  Last
Pages: 1 2 3 4
Prev: NetBeans Question
Next: Another NetBeans Question