dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPhagu Mahato
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » ASP.NET »

TextBox


Posted Date: 16 Jun 2008      Posted By:: narendra     Member Level: Silver    Member Rank: 1847     Points: 1   Responses: 13



hi friends plz help me.

I have one textbox.In textbox enter only numbers not characters.how validate the textbox data.

plz give the code || give the hint
plz explain with example

Regards
Narendra.




Responses

#249686    Author: Sujit Kumar      Member Level: Gold      Member Rank: 225     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

use regular expression

Regards,
Sujit Kumar
DotNet Blogs



 
#249692    Author: Madhavan      Member Level: Gold      Member Rank: 1561     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

hi,

write the following code in class file:

#region NumericValidationCheck

public bool IsNumeric(string strTextData)
{
string strLocal = strTextData;
Regex objNotPositivePattern = new Regex("[^0-9.]");
Regex objPositivePattern = new Regex("^[.][0-9]+$|[0-9]*[.]*[0-9]+$");
Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
if (!objNotPositivePattern.IsMatch(strLocal) && objPositivePattern.IsMatch(strLocal) && !objTwoDotPattern.IsMatch(strLocal))
return true;
else
return false;
}
#endregion

#region NumericValidationFunction

public bool IsNumericValidationFunction(string strTextboxData, out string strErrorMsg)
{
string strNumericLocal = strTextboxData;
bool IsReturn = IsNumeric(strNumericLocal);
if (IsReturn)
{
strErrorMsg = "";
return true;
}
else
{
strErrorMsg = "Input pattern is not correct....Enter valid number for ";
return false;
}
}
#endregion


In C# application:
use that class file dll and call the function like this...
class file: Validation.cs

string strerrmsg="";
Validation obj=new Validation();
obj.IsNumericValidationFunction(textbox1.text,out strerrmsg);
....
.

Regards,
Madhavan



 
#249693    Author: sreejith      Member Level: Gold      Member Rank: 0     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

use [0-9]as regular expression





 
#249694    Author: Anjali Sharma      Member Level: Gold      Member Rank: 1121     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

hi
try this using JavaScript
it will allows only numbers to enter not characters
var chkok="0123456789";
var chkstr=document.Form1.cname.value;
var allvalid=true;
for(i=0;i<chkstr.length;i++)
{
ch=chkstr.charAt(i);
for(j=0;j<chkok.length;j++)
if(ch==chkok.charAt(j))
break;
if(j==chkok.length)
{
allvalid=false;
break;
}
}
if(!allvalid)
{
alert("Enter only Numbers in TextBox");
document.Form1.cname.focus();
return false;
}



 
#249699    Author: sreejith      Member Level: Gold      Member Rank: 0     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

try this
<script language="JavaScript">
<!--
//Makes sure that the entered value is a number
// use via onKeyPress="checkNum()" on the textbox
function checkNum(){
var carCode = event.keyCode;if ((carCode < 48) || (carCode > 57)){
alert('Please enter only numbers.'); event.cancelBubble = true event.returnValue = false; }}
//--></script>



 
#249700    Author: soumya      Member Level: Silver      Member Rank: 0     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

can use regular expression
^[0-9]+$



 
#249711    Author: Debasmit Samal      Member Level: Gold      Member Rank: 484     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

On the KeyPress event of your textbox

if (Char.IsNumber(e.KeyChar) != true)
e.Handled = true;

Debasmit Samal



 
#249717    Author: pappan      Member Level: Gold      Member Rank: 0     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

hi,
Use filtertext box in ajax for number validation



 
#249719    Author: sachin Gopal      Member Level: Silver      Member Rank: 0     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

Use ajax control toolkit -FilterTextbox
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/FilteredTextBox/FilteredTextBox.aspx



 
#249736    Author: Kapil Dhawan      Member Level: Gold      Member Rank: 512     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

try this script for the code
function Num()
{
var Code = event.keyCode;if ((Code < 48) || (Code > 57))
{
alert('Numbers Only');
event.cancelBubble = true event.returnValue = false;
}
}

--
Regards,
Kapil



 
#249737    Author: Kiran Kumar Reddy      Member Level: Gold      Member Rank: 82     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 2

TextBox

Posted Date: 16 Jun 2008 Total Responses: 9
Posted By: narendra Member Level: Silver Points: 1



hi friends plz help me.

I have one textbox.In textbox enter only numbers not characters.how validate the textbox data.

plz give the code || give the hint
plz explain with example

Regards
Narendra.







use regular expression

Regards,
Kiran.



 
#249983    Author: Ratheesh      Member Level: Gold      Member Rank: 711     Date: 16/Jun/2008   Rating: 2 out of 52 out of 5     Points: 1

^[0-9]+$


 
#289466    Author: Ultimaterengan        Member Level: Gold      Member Rank: 9     Date: 29/Aug/2008   Rating: 2 out of 52 out of 5     Points: 2

hi,
Use RegularExpression for This purpose .

<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" Width="743px" >

<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
<asp:ListItem>d</asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Please Enter only Numeric" ValidationExpression="[0-9]*"></asp:RegularExpressionValidator>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="enter only Alpha-Numeric" ValidationExpression="[a-z]*"></asp:RegularExpressionValidator>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</div>
</form>




Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


http://renganathan1984.blogspot.com/



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : session in asp.net
Previous : TEXTBOx
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.