regular expressions with validators

Discussion in 'ASP .Net' started by =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Feb 6, 2007.

  1. Add a RequiredValidator also.
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Hayden Kirk" wrote:

    > Hi,
    >
    > I'm trying to validate an email address, which works, however, if there is
    > no text in the text box it still validates for some reason. Here is the
    > expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >
    > Thanks
    >
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Feb 6, 2007
    #1
    1. Advertising

  2. Hi,

    This should work:

    ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$

    Change the length you want (e.g. here it is minimum 2 character and maximum
    9 characters)

    Regards,
    Bhaskar

    "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in message
    news:...
    > Hi,
    >
    > I'm trying to validate an email address, which works, however, if there is
    > no text in the text box it still validates for some reason. Here is the
    > expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >
    > Thanks
    >
    Bhaskardeep Khaund, Feb 6, 2007
    #2
    1. Advertising

  3. Hi Hayden,

    I have been using this regex expression for IE 6.0 and above and
    firefox......please look up this page:

    http://msdn2.microsoft.com/en-us/library/ms998267.aspx

    Regards,
    Bhaskar



    "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in message
    news:%...
    > Hi
    >
    > Does not seem to work in IE or Firefox...
    >
    > Hrm :/
    >
    > "Bhaskardeep Khaund" <> wrote in message
    > news:emD$...
    >> Hi,
    >>
    >> This should work:
    >>
    >> ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
    >>
    >> Change the length you want (e.g. here it is minimum 2 character and
    >> maximum 9 characters)
    >>
    >> Regards,
    >> Bhaskar
    >>
    >> "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in
    >> message news:...
    >>> Hi,
    >>>
    >>> I'm trying to validate an email address, which works, however, if there
    >>> is no text in the text box it still validates for some reason. Here is
    >>> the expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >>>
    >>> Thanks
    >>>

    >>
    >>

    >
    >
    Bhaskardeep Khaund, Feb 6, 2007
    #3
  4. Hayden,

    If you use this method, you can write Dispaly="Dynamic" in both the
    validator controls, to remove the gap between the text of the error
    messages.

    Rgds,
    Bhaskar


    "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in message
    news:...
    > Hi Peter,
    >
    > If I use both, I get a gap between the validators, if you know what I
    > mean?
    >
    > After the box I have the regxp validator, then the one that checks for
    > some input, is there a away to get around that?
    >
    > Cheers,
    >
    > "Peter Bromberg [C# MVP]" <> wrote in
    > message news:...
    >> Add a RequiredValidator also.
    >> Peter
    >>
    >> --
    >> Site: http://www.eggheadcafe.com
    >> UnBlog: http://petesbloggerama.blogspot.com
    >> Short urls & more: http://ittyurl.net
    >>
    >>
    >>
    >>
    >> "Hayden Kirk" wrote:
    >>
    >>> Hi,
    >>>
    >>> I'm trying to validate an email address, which works, however, if there
    >>> is
    >>> no text in the text box it still validates for some reason. Here is the
    >>> expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >>>
    >>> Thanks
    >>>
    >>>
    >>>

    >
    >
    Bhaskardeep Khaund, Feb 6, 2007
    #4
  5. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    Hans Kesting Guest

    > Hi,
    >
    > I'm trying to validate an email address, which works, however, if
    > there is no text in the text box it still validates for some reason.
    > Here is the expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >
    > Thanks
    >


    That is by design: except for the RequiredFieldValidator, all validators
    treat an empty
    field as "valid".

    Hans Kesting
    Hans Kesting, Feb 6, 2007
    #5
  6. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    Hayden Kirk Guest

    Hi,

    I'm trying to validate an email address, which works, however, if there is
    no text in the text box it still validates for some reason. Here is the
    expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

    Thanks
    Hayden Kirk, Feb 6, 2007
    #6
  7. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    Hayden Kirk Guest

    Hi Peter,

    If I use both, I get a gap between the validators, if you know what I mean?

    After the box I have the regxp validator, then the one that checks for some
    input, is there a away to get around that?

    Cheers,

    "Peter Bromberg [C# MVP]" <> wrote in
    message news:...
    > Add a RequiredValidator also.
    > Peter
    >
    > --
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    >
    > "Hayden Kirk" wrote:
    >
    >> Hi,
    >>
    >> I'm trying to validate an email address, which works, however, if there
    >> is
    >> no text in the text box it still validates for some reason. Here is the
    >> expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >>
    >> Thanks
    >>
    >>
    >>
    Hayden Kirk, Feb 7, 2007
    #7
  8. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    Hayden Kirk Guest

    Hi

    Does not seem to work in IE or Firefox...

    Hrm :/

    "Bhaskardeep Khaund" <> wrote in message
    news:emD$...
    > Hi,
    >
    > This should work:
    >
    > ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
    >
    > Change the length you want (e.g. here it is minimum 2 character and
    > maximum 9 characters)
    >
    > Regards,
    > Bhaskar
    >
    > "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in
    > message news:...
    >> Hi,
    >>
    >> I'm trying to validate an email address, which works, however, if there
    >> is no text in the text box it still validates for some reason. Here is
    >> the expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >>
    >> Thanks
    >>

    >
    >
    Hayden Kirk, Feb 7, 2007
    #8
  9. =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    Hayden Kirk Guest

    Ah, simple as that.

    Thank you :)

    "Bhaskardeep Khaund" <> wrote in message
    news:...
    > Hayden,
    >
    > If you use this method, you can write Dispaly="Dynamic" in both the
    > validator controls, to remove the gap between the text of the error
    > messages.
    >
    > Rgds,
    > Bhaskar
    >
    >
    > "Hayden Kirk" <hayden dot kirk *@* mobilepc dot co dot nz> wrote in
    > message news:...
    >> Hi Peter,
    >>
    >> If I use both, I get a gap between the validators, if you know what I
    >> mean?
    >>
    >> After the box I have the regxp validator, then the one that checks for
    >> some input, is there a away to get around that?
    >>
    >> Cheers,
    >>
    >> "Peter Bromberg [C# MVP]" <> wrote in
    >> message news:...
    >>> Add a RequiredValidator also.
    >>> Peter
    >>>
    >>> --
    >>> Site: http://www.eggheadcafe.com
    >>> UnBlog: http://petesbloggerama.blogspot.com
    >>> Short urls & more: http://ittyurl.net
    >>>
    >>>
    >>>
    >>>
    >>> "Hayden Kirk" wrote:
    >>>
    >>>> Hi,
    >>>>
    >>>> I'm trying to validate an email address, which works, however, if there
    >>>> is
    >>>> no text in the text box it still validates for some reason. Here is the
    >>>> expression: \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    >>>>
    >>>> Thanks
    >>>>
    >>>>
    >>>>

    >>
    >>

    >
    >
    Hayden Kirk, Feb 7, 2007
    #9
    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. Jay Douglas
    Replies:
    0
    Views:
    591
    Jay Douglas
    Aug 15, 2003
  2. Ratman
    Replies:
    0
    Views:
    641
    Ratman
    Sep 14, 2004
  3. Burak Gunay

    Adding Regular Expression Validators to GridView

    Burak Gunay, Sep 20, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    789
    Burak Gunay
    Sep 20, 2006
  4. Burak Gunay

    Adding Regular Expression Validators to GridView

    Burak Gunay, Sep 19, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    130
    Burak Gunay
    Sep 19, 2006
  5. Noman Shapiro
    Replies:
    0
    Views:
    218
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page