Reply to Re: Regular expression

Your name:

Reply:


Posted by Hilarion on 11/29/05 17:02

> I want to check the input by a form field by PHP. I only want to allow
> capital or small letters, numbers, a - and a space. Now I use
> "[^A-Za-z0-9-]" . What do I need to add to allow spaces?


Shouldn't it have the "^" sign before the "["? Now it allows
everything beside letters, digits and a minus sign. You
should also add "*" after the "]" to allow not only one valud
character, but any number of it, and add "$" sign at the end
to prevent matching text that starts with valid characters,
but then contains invalido ones.
You can add space by prefixing it with backslash.

If you are using single quotes for the expression, then it should
be:

'^[\ A-Za-z0-9-]*$'

If you are using double quotes, then the backslash should be
escaped (to make it a part of the string, and not a PHP way
of escaping special character) by prefixing it with another
one (and you probably should escape the "$" sign too):

"^[\\ A-Za-z0-9-]*\$"

As you can see it's easier to use single quotes around regular
expressions.

Hilarion

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация