Regular Expression question

Discussion in 'ASP .Net' started by Brian Simmons, Aug 28, 2007.

  1. Hi All,

    I've got a textbox where I want to make sure the person has entered at least
    3 characters before submitting (it's like a partial name lookup type of
    query), so I don't want them to just enter "a" or "e" in the box and bring
    back everyone with an "a" or "e" in their name.

    I figure that a regular expression validation is the way to go, and I tried
    this:
    ValidationExpression="^([a-zA-z0-9\s]{3,255})$"

    However, this doesn't work all the time, because a user can enter "dr." or
    "st." and that is 3 characters but the validation fails, because the "." is
    not recognized as a character.

    So, can some kind soul help me out with the accurate regular expression for
    what I want to accomplish?

    Thanks,
    Brian
     
    Brian Simmons, Aug 28, 2007
    #1
    1. Advertising

  2. Hi Brian,
    Why a regular expression? I would just use "TextBox.Text..Length > 3".
    If you really want a regualr expression, try ".{3,255}". The "." will
    match anything (except newlines).
    Ethan

    Ethan Strauss Ph.D.
    Bioinformatics Scientist
    Promega Corporation
    2800 Woods Hollow Rd.
    Madison, WI 53711
    608-274-4330
    800-356-9526


    "Brian Simmons" wrote:

    > Hi All,
    >
    > I've got a textbox where I want to make sure the person has entered at least
    > 3 characters before submitting (it's like a partial name lookup type of
    > query), so I don't want them to just enter "a" or "e" in the box and bring
    > back everyone with an "a" or "e" in their name.
    >
    > I figure that a regular expression validation is the way to go, and I tried
    > this:
    > ValidationExpression="^([a-zA-z0-9\s]{3,255})$"
    >
    > However, this doesn't work all the time, because a user can enter "dr." or
    > "st." and that is 3 characters but the validation fails, because the "." is
    > not recognized as a character.
    >
    > So, can some kind soul help me out with the accurate regular expression for
    > what I want to accomplish?
    >
    > Thanks,
    > Brian
    >
    >
    >
     
    =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?=, Aug 28, 2007
    #2
    1. Advertising

  3. ValidationExpression= ".{3,255}"

    Btw the ^ and $ at the beginning and end of the expression are redundant in
    RegularExpressionValidator since the validation code checks that the match
    occurs at position zero and match length equals validated string length.


    "Brian Simmons" <> wrote in message
    news:...
    > Hi All,
    >
    > I've got a textbox where I want to make sure the person has entered at
    > least 3 characters before submitting (it's like a partial name lookup type
    > of query), so I don't want them to just enter "a" or "e" in the box and
    > bring back everyone with an "a" or "e" in their name.
    >
    > I figure that a regular expression validation is the way to go, and I
    > tried this:
    > ValidationExpression="^([a-zA-z0-9\s]{3,255})$"
    >
    > However, this doesn't work all the time, because a user can enter "dr." or
    > "st." and that is 3 characters but the validation fails, because the "."
    > is not recognized as a character.
    >
    > So, can some kind soul help me out with the accurate regular expression
    > for what I want to accomplish?
    >
    > Thanks,
    > Brian
    >
     
    Sherif Elmetainy, Aug 29, 2007
    #3
  4. Brian Simmons

    marss Guest

    On 28 , 20:01, "Brian Simmons" <> wrote:
    > Hi All,
    >
    > I've got a textbox where I want to make sure the person has entered at least
    > 3 characters before submitting (it's like a partial name lookup type of
    > query), so I don't want them to just enter "a" or "e" in the box and bring
    > back everyone with an "a" or "e" in their name.
    >
    > I figure that a regular expression validation is the way to go, and I tried
    > this:
    > ValidationExpression="^([a-zA-z0-9\s]{3,255})$"
    >
    > However, this doesn't work all the time, because a user can enter "dr." or
    > "st." and that is 3 characters but the validation fails, because the "." is
    > not recognized as a character.
    >
    > So, can some kind soul help me out with the accurate regular expression for
    > what I want to accomplish?
    >
    > Thanks,
    > Brian


    If you want limit possible characters with letters, numbers and dot:
    [a-zA-Z0-9\.]{3,}
    It can be shorter [\w\.]{3,} but in that case it also allows
    underscore.

    Regards,
    Mykola
    http://marss.co.ua
     
    marss, Aug 29, 2007
    #4
  5. Hello Sherif,

    > ValidationExpression= ".{3,255}"
    >
    > Btw the ^ and $ at the beginning and end of the expression are
    > redundant in RegularExpressionValidator since the validation code
    > checks that the match occurs at position zero and match length equals
    > validated string length.


    You might also want to take alook at this article:
    http://www.informit.com/articles/article.aspx?p=516589&seqNum=6&rl=1

    It describes how to make a CustomValidator which will do a length check.
    Should be quite simple to let it check both min and maxlength.



    > "Brian Simmons" <> wrote in message
    > news:...
    >
    >> Hi All,
    >>
    >> I've got a textbox where I want to make sure the person has entered
    >> at least 3 characters before submitting (it's like a partial name
    >> lookup type of query), so I don't want them to just enter "a" or "e"
    >> in the box and bring back everyone with an "a" or "e" in their name.
    >>
    >> I figure that a regular expression validation is the way to go, and I
    >> tried this:
    >> ValidationExpression="^([a-zA-z0-9\s]{3,255})$"
    >> However, this doesn't work all the time, because a user can enter
    >> "dr." or "st." and that is 3 characters but the validation fails,
    >> because the "." is not recognized as a character.
    >>
    >> So, can some kind soul help me out with the accurate regular
    >> expression for what I want to accomplish?
    >>
    >> Thanks,
    >> Brian

    --
    Jesse Houwing
    jesse.houwing at sogeti.n
     
    Jesse Houwing, Aug 29, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Munn

    Regular expression question...

    Andrew Munn, Jun 29, 2003, in forum: Perl
    Replies:
    1
    Views:
    2,139
    rakesh sharma
    Jun 30, 2003
  2. Glenn Kidd

    Regular expression question

    Glenn Kidd, Aug 18, 2003, in forum: Perl
    Replies:
    0
    Views:
    934
    Glenn Kidd
    Aug 18, 2003
  3. VSK
    Replies:
    2
    Views:
    2,311
  4. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    852
    Alan Moore
    Dec 2, 2005
  5. GIMME
    Replies:
    3
    Views:
    11,978
    vforvikash
    Dec 29, 2008
Loading...

Share This Page