473,503 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating Single Textbox with two validations

parshupooja
159 New Member
Hi
I am trying to validate one textbox for two validation condition in asp.net 2.0
1. Requiredfied
2. RegularExpression

i m not being able to work them together for one textbox. everytime only one is working at a time, if i put them together page gets stuck on regularexpression validation.

plz help
Jun 13 '07 #1
2 1466
nateraaaa
663 Recognized Expert Contributor
Hi
I am trying to validate one textbox for two validation condition in asp.net 2.0
1. Requiredfied
2. RegularExpression

i m not being able to work them together for one textbox. everytime only one is working at a time, if i put them together page gets stuck on regularexpression validation.

plz help
You should be able to do both. Here is some sample code:

Expand|Select|Wrap|Line Numbers
  1. function fnValidate(string) 
  2. {
  3. for (var i=0, output='', valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.- "; i<string.length; i++)
  4.  if (valid.indexOf(string.charAt(i)) != -1)
  5.  {
  6. output += string.charAt(i)
  7.  }
  8. return output.toUpperCase();
Expand|Select|Wrap|Line Numbers
  1. <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="The Client's Last Name is required" ControlToValidate="txtlastName"></asp:RequiredFieldValidator><br>
  2. <asp:textbox id="txtlastName" onkeyup="this.value = fnValidate(this.value);" tabIndex="2" Runat="server"></asp:textbox>&nbsp;Last Name of Client
  3. <asp:regularexpressionvalidator id="regxvLastName" runat="server" ValidationExpression="^[A-Z]*$" ControlToValidate="txtlastName"
  4. ErrorMessage="Enter Client's Last Name"></asp:regularexpressionvalidator>
Expand|Select|Wrap|Line Numbers
  1. if(txtlastName.Text == "")
  2. {
  3. lblSuccessFailure.Text = "You must enter the Client's last name";
  4. lblSuccessFailure.ForeColor = Color.Red;
  5. lblSuccessFailure.Visible = true;
  6. Page.RegisterStartupScript("SetFocus", "<script>document.getElementById('" + txtlastName.ClientID + "').focus();</script>");
  7. }
This should get you on the right track.

Nathan
Jun 13 '07 #2
parshupooja
159 New Member
Thank you for responding quick. Its working now that was my fault
Jun 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
5771
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
1
2877
by: panche | last post by:
I'm developing a fairly simple user control that has two textboxes for date/time entry (a from date/time and a to date/time). One of my requirements is that there should be no button that sets...
2
2108
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
2423
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
6
3112
by: Blinky | last post by:
Hi all, I have a dynamically generated page that can have 1 or more radio buttons. I am using javascript with onsubmit in the form statement to make sure a radio button is selected before...
7
1732
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
3
2785
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
1
3776
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
3
2025
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello everyone, I have an application windows , framework 2.0 + vs2005, and forms, with textboxes that I have validations of their values. Which is the fastest way to do this? using...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.