473,399 Members | 2,478 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,399 software developers and data experts.

Validation for the length of a textbox

I have the following regular expression and at present it checks that a field
contains only letters and is more than 2 characters in length. I would like
to change this slightly to also check that the text entered is 25 characters
or less. I'm not very good with regular expressions and was wondering if
someone could help me to do this.
My expression looks like the following: -

ValidationExpression="^[A-Za-z]{2,}$"

If i can't do this with a regular expression is there any other way I can do
this.

Cheers fo any help anyone can give me.

Jul 21 '05 #1
3 1414
Stephen,

I think that setting the maxlength to 25 in a textbox is the most easy way
to do that.

(Assuming that it is a winform textbox)

I hope this helps,

Cor
Jul 21 '05 #2
And as for the textbox allowing only text, try the keypress event...If
memory doesn't fail it may go like this...

If Char.IsLetter(e.KeyChar) = False Then
e.Handled = True
End If

Jul 21 '05 #3
> If i can't do this with a regular expression is there any other way I can
do this.

ValidationExpression="^[A-Za-z]{2,25}$"
But warning: there are a lot of languages with valid letters outside the
a-z range. If you want to accept accented character consider \w.
You can also use the IgnoreCase option.

And think twice how much you want to restrict the input.
You want digits only in phone numbers? What about 1-800-COLLECT
You want to restict the length of phone numbers? What about extensions?
You want to restrict the zip codes to digits only? What about Canadian
zip codes, that can have letters?
And so on.
I would say trust the user, validate length and that should do.

--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the contact choice. Right now it is set to enforce...
2
by: Robert Wagner | last post by:
I've created a page using VS.NET and page validator controls. The client side validation works fine on IE, but does not even activate under "alternate" browsers like Mozilla, Opera, etc. Why is...
10
by: A.M | last post by:
Hi, How can I use validation controls to check max length of string text boxes? Thanks, Alan
2
by: Oleg Ogurok | last post by:
Hi there, I have a modified ASP.NET TextBox control that formats its output as the phone number, e.g. if you enter "1234567890" it'll change the value to "123-456-7890". This is done by a...
1
by: Hong Hao | last post by:
Recently, I was trying to modify an existing aspx page when client-side validation on that page stopped working. I searched this group and the web in general and found that other people have had...
5
by: David | last post by:
Can anyone point me in the right direction. I am tring to ensure that the user input in a textbox is a Number. Any help would be great Thanks God Bless
0
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
1
by: rn5a | last post by:
A Web Form has a TextBox for users to enter their telephone numbers. I need to validate the TextBox against 3 conditions - firstly, the TextBox should allow only whole numbers (from 0 to 9)....
9
mageswar005
by: mageswar005 | last post by:
Hi Guys, My array textbox validation is not working fine,my code is given below please help me immediately. function validation() { var chks =...
2
by: mrutyunjaya | last post by:
hello, i have two textbox column and one button control in gridvie when i click button it will ask plese enter price in first textbox . when enter values it is asking again. how to pass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
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
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.