views:

262

answers:

2

I'm trying to use regular expression right now and I'm really confuse. I want to make some validation with this regular expression :

^[A-Za-z0-9_.][A-Za-z0-9_ ]*

I want to make it so there is a limit of character (32) and I want to "match" all the string.

ex:

string : ".hello hello" -this should work

string : ".hello hello /.." -This should be rejected because of the /..

Thanks!

+3  A: 

this?

^[A-Za-z0-9_.][A-Za-z0-9_ ]{0,31}$
SilentGhost
Why not 0,31 ?
Draemon
thanks Draemon, that prob better
SilentGhost
I'd start a debate about whether the "match all the string" requirement means that \Z should be used instead of $, but it's way past my bed-time, so I won't :-)
John Machin
A: 

From 0 to 32 chars:

^[\w\d_.]{0,32}$

seize