473,657 Members | 2,409 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. RegularExpressi on

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 regularexpressi on validation.

plz help
Jun 13 '07 #1
2 1469
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. RegularExpressi on

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 regularexpressi on 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
5788
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 to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
1
2889
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 these values (i.e., no button to cause a postback). The problem I'm having is that I need a number of validations to be performed on the data entry, but I don't know how to do this without having the user control/page posted back to the server. ...
2
2120
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 event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2432
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
6
3123
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 allowing the page to be submitted. At the moment it only works when there is 2 or more radio buttons on the page. How can I get the radio button validation working when there is only 1 radio on the page ?
7
1752
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 events do this for me, but my extended textbox doesn't get created by those wonderful form setup wizards. So, 1) Is there a way I can pick up these events without having to code for each control and without using custom extended controls, OR
3
2793
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
3790
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 on the form to reproduce this issue: ------------------------------------ Public Class Form1 Inherits Windows.Forms.Form
3
2035
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 validation with Enterprise Library? using errorProvider Validating and events? Please, samples codes about it...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.