Webmaster Forums Banner Professional Hosting from Just Host
Welcome Guest Search | Active Topics | Members | Log In | Register

run time numeric data validation on textbox Options
Azaz
Posted: Thursday, May 22, 2008 6:39:56 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 59
Points: 177
Location: Pakistan
hi all

i have a text box for quantity. i want to restrict users to put only numeric data not alphabet ( a-z ).

any idea how to do that???
Sponsor
Posted: Thursday, May 22, 2008 6:39:56 AM
kirshana
Posted: Thursday, May 22, 2008 6:41:34 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 80
Points: 143
Location: India
u better use required field validation controls they are very easy to use and fulfill your requirements
Azaz
Posted: Thursday, May 22, 2008 6:43:48 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2008
Posts: 59
Points: 177
Location: Pakistan
kirshana wrote:
u better use required field validation controls they are very easy to use and fulfill your requirements


required field validators check data only on pag load. i want some thing on run time. i think javascript might helps me but i don't know how
ca4nul
Posted: Thursday, May 22, 2008 6:53:20 AM

Rank: Advanced Member
Groups: Member

Joined: 11/9/2007
Posts: 223
Points: 575
Location: UK
Azaz wrote:
hi all

i have a text box for quantity. i want to restrict users to put only numeric data not alphabet ( a-z ).

any idea how to do that???



hi

lets say you have a text box of name "Qty" as below;

Code:

<asp:TextBox ID="Qty" runat="server" MaxLength="5" Width="30px" ></asp:TextBox>


and you write this line in page load event

Code:

Qty.Attributes.Add("onkeypress","return isNumberKey(event)");


then on aspx you copy and past following javascript function.

Code:


<script language="javascript" type="text/javascript">
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
    return false;

return true;
}

</script>




i have tried it works. i hope that will solve your problem!

Happy Coding Bye
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by HaqTech.Com
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 2.147 seconds.