Validation for the length of a textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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
 
If i can't do this with a regular expression is there any other way I can
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.
 
Back
Top