Subscribe to Subscribers

Forums » .NET » Visual Studio »

Problem while working with validation controls


Posted Date: 04 Aug 2012      Posted By:: lakshmi sreeja     Member Level: Bronze    Member Rank: 2387     Points: 2   Responses: 3



hi....,
i'm working with microsoft visual studio 2008.i have phone no,username and password fields in my page.i want to use validators for these fields.can anyone tell how to use those validators..?




Responses

#683065    Author: SURESH R      Member Level: Gold      Member Rank: 191     Date: 04/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

Hai,
For username and password You use Requiredfield validator this is a basic and most used one.
For phone number use Regular expression validator this will check whether the give number is number/phonenumber.It raise an when u use character or any other special symbols.
using Required field is easy just place it near username textbox and set the property "controltovalidate" as username textbox name for eg:txtuser.Continue same for password

When u use regularexpression validator we need to use a regular
expression.

Set Expression property as ^[0-9]{10}

Try this.


R.SURESH


 
#683078    Author: saravanakumar      Member Level: Gold      Member Rank: 196     Date: 04/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

this is for username and password fields,
 <asp:TextBox ID="UserName" runat="server" Font-Size="0.8em"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>


this is for phone number,

<asp:TextBox ID="txtqty" runat="server" TabIndex="6" MaxLength="10" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RequiredFieldValidator ID="Rfvquty" runat="server" ControlToValidate="txtqty"
ErrorMessage="Enter the Material Quantity" ForeColor="Red" SetFocusOnError="True" InitialValue="0"
ValidationGroup="valnewmaterial">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtqty"
ErrorMessage="Please Enter Only Numbers" ValidationExpression="^\d+$" ValidationGroup="valnewmaterial">*</asp:RegularExpressionValidator>


 
#683095    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 04/Aug/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

Refer this example code


<asp:ValidationSummary ID="ValidationSummary1" runat="server" /><br />

Enter your Phoneno <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Enter your user id <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
Enter your Password<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox><br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Phone No. cannot be blank"
Display="None" ControlToValidate="TextBox1"></asp:RequiredFieldValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="User Id cannot be blank"
Display="None" ControlToValidate="TextBox2"></asp:RequiredFieldValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Password cannot be blank"
Display="None" ControlToValidate="TextBox3"></asp:RequiredFieldValidator><br /><br />

<asp:Button ID="Button1" runat="server" Text="Submit" />


Regards
N.Ravindran
Your Hard work never fails





 
Post Reply
You must Sign In to post a response.

Next : How to show and hide controls? Help please Urgent....
Previous : This code is not working properly, please solve this.
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 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.