Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: stuck on regexp

by jimbobn (Novice)
on Aug 25, 2002 at 12:15 UTC ( [id://192663]=note: print w/replies, xml ) Need Help??


in reply to Re: stuck on regexp
in thread stuck on regexp

thanks for that guys.
hotshot, is your rexexp missing out a _ or does the \w cater for that?

Just out of interest, is it possible to specify the minimum/maximum lengh of a variable using a regexp?
i.e, if i want the username to be no longer than 30 characters.

Replies are listed 'Best First'.
Re: Re: Re: stuck on regexp
by moxliukas (Curate) on Aug 25, 2002 at 13:00 UTC

    To make the username no longer than 30 characters use this:

    /^[A-Za-z][-.\w]{1,29}$/

    This will match when the first character is [A-Za-z] and is followed by 1 to 29 characters of form [-.\w] (thus making the total length of username from 2 to 30 characters)

    And yes, \w caters for [a-zA-Z0-9_]

      if single character usernames are allowed, {1,29} should be replaced by {0,29}

      ~Particle *accelerates*

      thanks guys. You rule :-)
Re: Re: Re: stuck on regexp
by hotshot (Prior) on Aug 25, 2002 at 12:32 UTC
    \w stands for a-z, A-Z, 0-9 and the underscore (_) os it answers your question.
    about your second question, of course you can limit the string's length, for example if a username length should be maximum 30 characters long than this will qualify:
    /^[A-Za-z][-.\w]{29}$/
    the first char is mandetory to be alphabetic and the 29 in braces replaces the '+' sign to note exact number of chars.

    Hotshot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://192663]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-23 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found