Validate string in regular expression

Hi

I wanted to validate a name input in my project to check if it contains only characters or number and special characters like .(dot), -(hyphen) or _(underscore)

I have formed this regular expression to check that:

if(l_name.matches("[A-Za-z0-9._-]" ) )

I am not sure whether it is right..anyway it does not work.

Can somebody please correct me what is going wrong and suggest me how to make it work for my validation?

Thanks,

[474 byte] By [Sujiea] at [2007-11-27 10:14:30]
# 1

> I have formed this regular expression to check that:

>

> if(l_name.matches("[A-Za-z0-9._-]" ) )

>

> I am not sure whether it is right..anyway it does not

> work.

You simply need to add a quantifier to your expression, which currently means one character in the class [A-Za-z0-9._-]

What about : "[A-Za-z0-9._-]+"

TimTheEnchantora at 2007-7-28 15:33:42 > top of Java-index,Java Essentials,Java Programming...
# 2

You're just missing a plus sign: if (l_name.matches("[A-Za-z0-9._-]+" ) )

uncle_alicea at 2007-7-28 15:33:42 > top of Java-index,Java Essentials,Java Programming...
# 3

Hey thanks a lot..it worked..

i just missed a +..:-)

Sujiea at 2007-7-28 15:33:42 > top of Java-index,Java Essentials,Java Programming...