You are here: Re: validate file name using regular expression « All PHP « IT news, forums, messages
Re: validate file name using regular expression

Posted by Bosconian on 07/19/06 19:34

"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:e7f2f$44be0ece$8259c69c$22749@news2.tudelft.nl...
> Bosconian wrote:
>> "Bosconian" <nobody@nowhere.com> wrote in message
>> news:a9adnRNNhaRVJSDZnZ2dnUVZ_vmdnZ2d@comcast.com...
>>> I need a regular expression to validate characters for a given file
>>> name. I want to limit valid characters to the following:
>>>
>>> a-z
>>> A-Z
>>> 0-9
>>> underscores
>>> hyphens
>>> white spaces
>>>
>>> The file name must end with a period and a 3-character extension.
>>>
>>> I also want to prevent repeat underscores, hyphens and white spaces.
>>> Example: "__", "--" and " " would all be invalid.
>>>
>>> I found this example:
>>>
>>> ^[a-zA-Z0-9_\s-]+$
>>>
>>> This comes close, but it allows repeat underscores, hyphens and white
>>> spaces. It also uses "\s" which allows carriage returns, linefeeds,
>>> tabs, etc.
>
> I thought you wanted to allow whitespaces?
>
>>> Any help would be greatly appreciated.
>>>
>>>
>>
>> I almost have it:
>>
>> $pattern = "|[\wa-zA-Z0-9\-_]+\.[a-zA-Z0-9]{3}$|";
>
> If you eant a WHOLE string to match, enchor it with both ^ and $
>
> /^([a-z0-9]+[\040_\-]?)*\.[a-z]{3}$/i
>
> Grtz,
> --
> Rik Wasmus
>
>

What about preventing a space before the period? For example: filename .txt

 

Navigation:

[Reply to this 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

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