C# .NET - accepting numerics in a textbox in asp.net with c sharp
Asked By saran vasan
10-Feb-12 04:47 AM
how to give only numerics values in a text box in asp.net and c sharp with out using javascript
Reena Jain replied to saran vasan
Hi,
Here is javascript code for you
function fn_validateNumeric(thi,e)
{
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (((keycode>=65) && (keycode<=90))||((keycode>=97) && (keycode<=122)))
{
return true;
}
else
{
return false;
}
}
saran vasan replied to Reena Jain
how to give only numerics values in a text box in asp.net and c sharp without using javascript
Somesh Yadav replied to saran vasan
Hi,
here is the code for giving only numerics value in text box.
private void rtbQuantity_TextChanged(object sender, EventArgs e)
{
rtbQuantity.KeyPress += new
KeyPressEventHandler(rtbQuantity_KeyPress);
}
private void rtbQuantity_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0') || (e.KeyChar > '9')) e.Handled = true;
}
dipa ahuja replied to saran vasan
Numeric and .
<script type="text/javascript">
function chk(obj) {
obj.value = obj.value.replace(/[^0-9.]/gi, '')
}
</script>
<input type="text" value="" onkeyup="chk(this)"/>
Dilip Sharma replied to saran vasan
then u have to use asp.net validation control
but it will only check after type value in text box.......
Reena Jain replied to saran vasan
Hi,
if you want to validate the textbox for number only then you can use regular expression validation like this
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="only Numberallowed" ControlToValidate="TextBox1"
ValidationExpression="^[0-9]*$"></asp:RegularExpressionValidator>

Validation Checking Hi Friends, in my project i am using asp.net with c#. without using validation controls i want to check validation for textbox. urgent. 1) only strings parseInt(num.value); if (!isNaN(No)) { if ((No > = 0) && (No < = 30)) { return true ; } } else { alert( "Numerics only." ); num.value = "" ; num.focus(); return false ; } } else { return false ; } If you dont want to ME KNOW. Thanks thats working fine. but the characters that are entered is displayed (ie accepting) in the textbox, but it shoud'nt be. how to handle this. i handled the code, so that is can help you. This is the aspx page code. <%@ Page Language = "C#" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inherits = "_Default" %> <!DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1
stl clear and erase. C++ / VB , clear, and, erase." / > Hello, The following resulted from a performance hotspot analysis in a and the old contents are left as garbage. Could I be better off using old C arrays? Any hint greatly appreciated, this is really a hotspot in my program. Regards, Peter - - [ See http: / / www.gotw.ca / resources / clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this C++ Discussions Translation (1) Destructor (1) Exception (1) Relative (1) Class (1) Bit (1) Bremen Daniel Kr?gler - - [ See http: / / www.gotw.ca / resources / clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Are you compiling with optimizations enabled? Compiling without optimizations similar. -Ed - - [ See http: / / www.gotw.ca / resources / clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] First of all, thank you for taking the time Thanx Peter - - [ See http: / / www.gotw.ca / resources / clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Isn't this similar to the problem of constructing a vector of int of a particular size, which in C++98 requires the constructor to be called for each of the vector's elements (so
site for F# users. http: / / research.microsoft.com / fsharp / fsharp.aspx http: / / cs.hubfs.net / C# Discussions LINQ (1) OP (1) Database (1) I've got to say, Robert. . .seeing you website. BTW, the F# team claims the performance of F# is as good as native C++, and I did see the LINQ at F# when we are still using .Net 1 and not enough to time to learn them before the next "greatest" thing comes along. C# and / or C++ offer almost everything one needs today notwithstanding their imperfections. Performance also isn't the issue major improvement over existing languages, I say enough already (and BTW, comparisons with a good C++ compiler usually don't pan out in practice). Okay - I admit it - I'm trying as well and generally there it has been well received. I posted it to the C# and VB groups because generally when C# or VB programmers they have often heard of F# and are interested in knowing a to people who have positive contributions to make. Indeed, I'm here trying to learn C#. I think you'll find the C++ users and users of various functional programming languages
C# with XP look .NET Framework Hi guys. I am newbie in C#. I have a project written in MS VisualStudio 2008, C#. So when I execute the project (Windows Forms Application) on the same machine when MSVS2008 look on any machine, regardless if MSVS2008 installed or not, and how. Thanks in advance. C# Discussions Environment.OSVersion.Version.Major (1) Environment.OSVersion.Version.Minor (1) OSFeature.Feature.IsPresent (1 0. - - Web site: http: / / www.pobox.com / ~skeet Blog: http: / / www.msmvps.com / jon.skeet C# in Depth: http: / / csharpindepth.com Hi. I installed .Net Framework 3.0 and 3.5 com> Web site: http: / / www.pobox.com / ~skeet Blog: http: / / www.msmvps.com / jon.skeet C# in Depth: http: / / csharpindepth.com Just because WPF is available, doesn't automatically mean it M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ M_ __ __ __ __ __ __ _ \ `C! `C! `C! `C! `C! `C! `C! `C! `C! `C! `C! ` MC! `C! `C! `C! `C! `C