Re: Generic file name validation code?



Arne Vajhøj wrote:
harryajh wrote:
On 2 Sep, 12:40, Roedy Green <see_webs...@xxxxxxxxxxxxxxxxxxxx> wrote:
On Sun, 02 Sep 2007 11:15:34 GMT, "harry" <a...@xxxxxxx> wrote, quoted or
indirectly quoted someone who said :
Does anybody know of java code that does this?
If you limited the name to A-Z a-z 0-9 . it would work on anything
without a tight length limit anything.

Thanks Roedy, this seems to do the job (forgot to say file name must
end with "con")

> Pattern p = Pattern.compile("([A-Z]|[a-z]|[0-9])+.con");

That can be abbreviated to:

Pattern p = Pattern.compile("([A-Za-z0-9])+.con");

Better quote that . character ... Also, the ( ) can be
eliminated if the O.P. doesn't need the capturing group.

--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxxx
.



Relevant Pages