Regular Expressions with ASP.NET
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Info@slickworm.com
-- Moved from [aspclient] to [aspngregexp] by Ken Schaefer <Click here to reveal e-mail address> --

I am making a few textbox controls whos values will be added together( so the
input will obviously have to be in the form of an integer).

I will also have form validation controls in this form, and I don't want the
add button to cause validation.

With that, i am going to make a server side validation script that will add the
value of the two text boxes only if they are numbers. I am not too sure what
I'm doing here, but all i know is that 7 hours of my research through
documentation and internet info hasn't helped me at all. I hope someone here
will.
Here is what i have so far...

<%@ Page Language="VB" %>
<Script Language="VB" Runat="Server">
    Sub Text_Change(obj as object, e as eventargs)

    End Sub
    Sub Button_Cont(obj as object, e as eventargs)
        Dim r as New RegEx("[0-9]*")
        Dim m as Match = r.match(tb1.text)
        If m.empty is "1" then
            response.write("No go!")
Else
response.write("Yes!")
        End If
    End Sub
</Script>
<Html>
<Body>
<Form runat="Server">
<asp:textbox id="tb1" OnTextChanged="Text_Change" runat="Server" />

<asp:textbox id="tb2" OnTextChanged="Text_Change" runat="Server" />

<asp:button id="add" OnClick="Button_Cont" Text="Add" runat="Server" />
</form>

Reply to this message...
 
    
Bob Levittan (VIP)
The asp button objects (asp:button, asp:linkbutton, etc) have a
'CausesValidation' property that, when set to 'False', prevents validation
from occuring when the button is clicked.

----Original Message Follows----
From: Click here to reveal e-mail address
Reply-To: "aspngregexp" <Click here to reveal e-mail address>
To: "aspngregexp" <Click here to reveal e-mail address>
Subject: [aspngregexp] Regular Expressions with ASP.NET
Date: Fri, 15 Mar 2002 00:56:01 -0500 (EST)

-- Moved from [aspclient] to [aspngregexp] by Ken Schaefer
<Click here to reveal e-mail address> --

I am making a few textbox controls whos values will be added together( so
the
input will obviously have to be in the form of an integer).

I will also have form validation controls in this form, and I don't want the
add button to cause validation.

With that, i am going to make a server side validation script that will add
the
value of the two text boxes only if they are numbers. I am not too sure what
I'm doing here, but all i know is that 7 hours of my research through
documentation and internet info hasn't helped me at all. I hope someone here
will.
Here is what i have so far...

<%@ Page Language="VB" %>
<Script Language="VB" Runat="Server">
    Sub Text_Change(obj as object, e as eventargs)

    End Sub
    Sub Button_Cont(obj as object, e as eventargs)
        Dim r as New RegEx("[0-9]*")
        Dim m as Match = r.match(tb1.text)
        If m.empty is "1" then
            response.write("No go!")
Else
response.write("Yes!")
        End If
    End Sub
</Script>
<Html>
<Body>
<Form runat="Server">
<asp:textbox id="tb1" OnTextChanged="Text_Change" runat="Server" />

<asp:textbox id="tb2" OnTextChanged="Text_Change" runat="Server" />

<asp:button id="add" OnClick="Button_Cont" Text="Add" runat="Server" />
</form>
| [aspngregexp] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Reply to this message...
 
    
Wayne King
Is this what you're trying to do in your button click handler?:
Sub Button_Cont(obj as object, e as eventargs)
Dim r as New RegEx("^\d+$")
If r.IsMatch(tb1.Text) AndAlso r.IsMatch(tb2.Text) Then
Trace.Write("Both are integers");
Else
Trace.Write("Both are not integers");
End If
End Sub

This pattern would permit whitespace before or after the number (but not =
within the number):
^\s*\d+\s*$

-----Original Message-----
From: Bob Levittan [mailto:Click here to reveal e-mail address]

The asp button objects (asp:button, asp:linkbutton, etc) have a=20
'CausesValidation' property that, when set to 'False', prevents =
validation=20
from occuring when the button is clicked.

----Original Message Follows----
From: Click here to reveal e-mail address

I am making a few textbox controls whos values will be added together( =
so=20
the
input will obviously have to be in the form of an integer).

I will also have form validation controls in this form, and I don't want =
the
add button to cause validation.

With that, i am going to make a server side validation script that will =
add=20
the
value of the two text boxes only if they are numbers. I am not too sure =
what
I'm doing here, but all i know is that 7 hours of my research through
documentation and internet info hasn't helped me at all. I hope someone =
here
will.
Here is what i have so far...

<%@ Page Language=3D"VB" %>
<Script Language=3D"VB" Runat=3D"Server">
    Sub Text_Change(obj as object, e as eventargs)

    End Sub
    Sub Button_Cont(obj as object, e as eventargs)
        Dim r as New RegEx("[0-9]*")
        Dim m as Match =3D r.match(tb1.text)
        If m.empty is "1" then
            response.write("No go!")
Else
response.write("Yes!")
        End If
    End Sub
</Script>
<Html>
<Body>
<Form runat=3D"Server">
<asp:textbox id=3D"tb1" OnTextChanged=3D"Text_Change" runat=3D"Server" =
/>

<asp:textbox id=3D"tb2" OnTextChanged=3D"Text_Change" runat=3D"Server" =
/>

<asp:button id=3D"add" OnClick=3D"Button_Cont" Text=3D"Add" =
runat=3D"Server" />
</form>

Reply to this message...
 
 
System.Diagnostics.Trace




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com