Add two number if it contains character with digit

Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 943
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication18.WebForm3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt1" ErrorMessage="Insert values"></asp:RequiredFieldValidator>
<br />
<asp:TextBox ID="txt2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txt2" ErrorMessage="Insert values"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="btn_add" runat="server" Text="Add" onclick="btn_add_Click" />


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace WebApplication18
public partial class WebForm3 : System.Web.UI.Page

protected void btn_add_Click(object sender, EventArgs e)
string s1 = txt1.Text;
string s2 = txt2.Text;

int i1 = Convert.ToInt32(Regex.Replace(s1, "[^0-9]", ""));
int i2 = Convert.ToInt32(Regex.Replace(s2, "[^0-9]", ""));

int Result = i1 + i2;

Comments or Responses

Posted by: Learningtorise on: 4/15/2013 Level:Starter | Status: [Member] | Points: 10

Posted by: Learningtorise on: 4/15/2013 Level:Starter | Status: [Member] | Points: 10

Login to post response