473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

validating text entered in text box

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 3291
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 Expert Mod 8TB
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
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 Expert Mod 8TB
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
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...
2
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...
0
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...
1
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...
0
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,...
9
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. ...
2
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...
232
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...
8
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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...
0
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
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...

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.