Forums » .NET » ASP.NET »

Enter only 10 digits in text box in asp.net


Posted Date: 22 Aug 2012      Posted By:: kavitha     Member Level: Silver    Member Rank: 733     Points: 1   Responses: 8



hi friends,


how to enter only 10 digits in text box in asp.net.

not maximum or minimum.

please give the solution,

thanks.




Responses

#685151    Author: RayalaHariKishore      Member Level: Gold      Member Rank: 56     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

hi use TextBox1.Text.Length property to check whether it has 10 values or not if not display error.

Rayala HariKishore

try..try..try...you achieved it.
http://rayalaharikishore.wordpress.com/


 
#685156    Author: Ashis kumar Nayak      Member Level: Gold      Member Rank: 0     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 2

use Regx in Javascript to achive this on key press.

expression ="^[0-9]{10}"

it's allow u to enter only 10 digit muneric value.


 
#685160    Author: kavitha      Member Level: Silver      Member Rank: 733     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

please give in detail,

i am not understand.





 
#685161    Author: Mahesh Durgam      Member Level: Gold      Member Rank: 54     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

You can use the Regular Expression validator to restrict the user to enter 10 digits



<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^\d{10}$" ErrorMessage="Error Message"></asp:RegularExpressionValidator>




Thanks,
Mahesh

Thanks,
Mahesh


 
#685165    Author: Anil Kumar Pandey      Member Level: Diamond      Member Rank: 1     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 2

You can set the maximum length of the text box as below.


<asp:TextBox ID="Value1"
Columns="2"
MaxLength="3"
Text="1"
runat="server"/>


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM


 
#685171    Author: kavitha      Member Level: Silver      Member Rank: 733     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 1

thanks,

its working.


 
#685172    Author: saravanakumar      Member Level: Gold      Member Rank: 491     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 3

try this,

<asp:Label ID="lblphno" runat="server" Text="Mobile Number"></asp:Label>
<asp:TextBox ID="txt_phno" MaxLength="10" runat="server" TabIndex="6" > </asp:TextBox>
//textbox control with maximum limit of 10 digits
<asp:RequiredFieldValidator ID="Rfvphno" runat="server" ControlToValidate="txtqty"
ErrorMessage="Enter the Phone Number" ForeColor="Red" SetFocusOnError="True"
ValidationGroup="valnewmaterial">*</asp:RequiredFieldValidator>
// require field validator for checking the field is empty means display the error message
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txt_phno"
ErrorMessage="Please Enter Only Numbers" ValidationExpression ="^\d+$" ValidationGroup="valnewmaterial">*</asp:RegularExpressionValidator>
// regular expression for user enters alpha char means diplay the error message.


 
#685174    Author: RayalaHariKishore      Member Level: Gold      Member Rank: 56     Date: 22/Aug/2012   Rating: 2 out of 52 out of 5     Points: 2

hi,
you can use it in two ways one is using c code using the property of textbox and other is using using regular expression (in this you can use regularexpression validator or js code.)

first take the textbox and put the regularexpressionvalidator control and goto its properties and then choose validationexpression and there you put \d[10] it means it checks for length is 10 or not. done

second is you can use in cs code that is when you are leaving the control means when focus is leaving the control you can fire event and check whether the length is 10 or not or while submitting it's length is 10 or not. suppose submit in click event use the if(Textbox1.Text.Length != 10 ) {messagebox.show("length must be 10");} like this you can use and for leaving the focus it is done in windows application here you can use textchanged event for this use same length property
you can choose any way.
any way but for client side validation use js code only. means use the regular expression.

Rayala HariKishore

try..try..try...you achieved it.
http://rayalaharikishore.wordpress.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 : What is the difference between single sign on and claim base authentication?
Previous : How to encrypt a query string that is passed by a hyperlink on a gridview C#
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India