473,623 Members | 3,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validating text entered in text box

86 New Member
Hi friends,

i am using .net 2005 but we dont use validation controls.
my requirement is that i have to limit user entering only alpha values in "first name" and "last name" fields.

the page has some text box and a submit button.
on clicking the submit buttion the validation must be done in java script.

how can i limit user to my requirement?


thank you
Nov 26 '08 #1
4 3304
ravindarjobs
86 New Member
i have used this code. It is working a bit fine.

Expand|Select|Wrap|Line Numbers
  1.  var regexAlpha=/[a-zA-z]/;
  2.     if(!regexAlpha.test(document.getElementById('ctl00_DefaultContent_txtFristName').value.trim()))
  3.     {
  4.         alert('First Name Should Contain only Alphabet values');
  5.         return false;
  6.     }
suppose if we enter values liks "2345" in the text box then it is giving error. but if we enter text like "sdfa234234 " it is not giving error.

what changes should i make to it to accept only alphabets with spaces?
Nov 26 '08 #2
acoder
16,027 Recognized Expert Moderator MVP
You need to constrain the whole input:
Expand|Select|Wrap|Line Numbers
  1. var regexAlpha=/^[a-z ]+$/i;
The i makes it case-sensitive to match all cases. ^ and $ are start and end match characters.

PS. please use [code] tags when posting code.
Nov 26 '08 #3
ravindarjobs
86 New Member
thank you Acoder.

that is a good information.

belive or unbelieve i was blindly working on these regular expressions for more than a day now and i used to think "$" is used for "space".


thank you
Nov 26 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
No problem at all.

For regular expressions, this is a good resource.
Nov 26 '08 #5

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

Similar topics

3
13997
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it dosent meet these requirments an error message will be displayed. I have pasted the code (and highlighted the relevant parts) below in the hope that someone can help me out with this. Ive been trying to suss it out all week & it's driving me nuts!...
2
3667
by: Andrea | last post by:
If anyone has a simple routine to validate that text entered in a text box control contains only numbers (zip code) or only alpha characters (name), can you please send me? I'm new to this, and am not looking in the right places to find answers. Thanks! Andrea
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...
1
5265
by: cemcat | last post by:
Hello, We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to enter multiple e-mail addresses separated by semicolons. We need to validate that each individual e-mail address entered is a valid e-mail address format. We've added a CustomValidator to perform this validation. We have the server-side validation working fine, but now we need to add some client-side validation via JavaScript. We are having difficulties...
0
1801
by: Wayne Phipps | last post by:
Hi There, I want to be able to validate data entered by a user onto a form. Different fields will have different validation requirements. As an example, a text box may only allow numeric, alpha or alpha numeric entry and/or may have limitations on length or value. I thought about inheriting a control from one of the standard forms controls
9
5832
by: chuck | last post by:
I need some help with validating user input. I am writing a C computer program for an intro to C course. Here is the situation. I am creating an application that will do currency conversions. The user will be presented with a list of 5 selections they can make. They will then be prompted for which selection they want to enter (which can only be 1-5, no characters or anything like it). Once they select the number, 1 for Euro, 2 for...
2
1162
by: Fred G. Sanford | last post by:
I have two text boxes. If (and only if) a user enters something in textbox1, I need to validate that they also entered something in Textbox2. IOW, I need to validate that they entered something in textbox1...and if they did...validate that they entered something in textbox2. Is there an easy way to do this, like with Validation controls? TIA for any help, fgs
232
13239
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
8
4122
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has prevailed it just is :) My problem is this im trying to validate the contents of a textbox (it has to be a normal textbox) and on a c# winforms and i am calling the textbox validating
0
8162
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
8662
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...
1
8317
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
8463
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...
0
7134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6104
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
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2593
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 we have to send another system
1
1769
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.