From: Ashley Sheridan on
On Tue, 2010-06-01 at 17:32 +0100, Richard Quadling wrote:

> On 1 June 2010 16:38, Ashley Sheridan <ash(a)ashleysheridan.co.uk> wrote:
> > Ah, I ought to have guessed as it's you! ;)
>
> What are you insinuating?
>
> --
> -----
> 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
>


I've never known anyone to optimise code quite as much as you! That's
not a bad thing though.

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


From: Peter on
Hi Tanel,

1. only letters

$str = 'helloworld';

if(preg_match("/^[a-zA-Z]*$/",$str))
echo "only letters";
else
echo "failed";

2. only letters and spaces

$str = 'hello world';

if(preg_match("/^[a-zA-Z\s]*$/",$str))
echo "only letters and spaces";
else
echo "failed";


Regards
Peter.M

Tanel Tammik wrote:
> How to check with regular expression (preg) if string has:
>
> 1. only letters
> 2. only letters and spaces
>
> Br
> Tanel
>
>
>
>
From: Richard Quadling on
On 2 June 2010 06:12, Peter <peters(a)egrabber.com> wrote:
> Hi  Tanel,
>
> 1. only letters
>
> $str = 'helloworld';
>
> if(preg_match("/^[a-zA-Z]*$/",$str))
> echo "only letters";
> else
> echo "failed";
>
> 2. only letters and spaces
>
> $str = 'hello world';
>
> if(preg_match("/^[a-zA-Z\s]*$/",$str))
> echo "only letters and spaces";
> else
> echo "failed";
>
>
> Regards
> Peter.M

Be careful with using *.

The issue of a zero length string is important.

* will allow a zero length string.

++ will force the regex to match something, so zero length strings are rejected.



/s will match space, formfeed, newline, carriage return, horizontal
tab, and vertical tab

So a string with newlines (for example a <textarea> with line breaks)
would match.





--
-----
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: "Jan G.B." on
2010/6/1 Peter Lind <peter.e.lind(a)gmail.com>:
> On 1 June 2010 17:33, Ashley Sheridan <ash(a)ashleysheridan.co.uk> wrote:
>> 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?
>>
>
> Equally important: why have three people already done this persons
> homework. 5 minutes googling would have answered this ...
>

Even more important: No answer is correct, because f.e. "äüßćéâ" are
also letters.

Bye

;-)
From: Richard Quadling on
On 2 June 2010 16:35, Jan G.B. <ro0ot.w00t(a)googlemail.com> wrote:
> 2010/6/1 Peter Lind <peter.e.lind(a)gmail.com>:
>> On 1 June 2010 17:33, Ashley Sheridan <ash(a)ashleysheridan.co.uk> wrote:
>>> 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?
>>>
>>
>> Equally important: why have three people already done this persons
>> homework. 5 minutes googling would have answered this ...
>>
>
> Even more important: No answer is correct, because f.e. "äüßćéâ" are
> also letters.
>
> Bye
>
> ;-)
>

So, would ...

/^[^\p{M}\p{Z}\p{N}\p{P}\p{S}\p{C}\d\s]++$/i

be ok?



--
-----
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
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: NetBeans Question
Next: Another NetBeans Question