Creating a validating textbox control

  • Thread starter Thread starter Imran Hayat
  • Start date Start date
I

Imran Hayat

Hello! I'm trying to create a control (inheriting from
the Textbox) that will allow the user's entered text to
be reformatted when the user leaves the control. I plan
to use this control to allow the user to enter things
such as a telephone number or postal code, etc. and
specify to the control what the input'ed text should be
re-formatted into.

So if the user enters 3334842989 and leaves the textbox,
it should automatically reformat the entered text into:
(333) 484-2989.

Could someone point me in the right direction as to how I
can do this? I already have a control like this for
datetime values, and that is easy because I just specify
to the control the formatting expression to pass to the
DateTime.tostring(format) mathod to re-format the entered-
in value. Now I just need to do this for a string based
input variable.

Thanks in advance!
 
* "Imran Hayat said:
Hello! I'm trying to create a control (inheriting from
the Textbox) that will allow the user's entered text to
be reformatted when the user leaves the control. I plan
to use this control to allow the user to enter things
such as a telephone number or postal code, etc. and
specify to the control what the input'ed text should be
re-formatted into.

So if the user enters 3334842989 and leaves the textbox,
it should automatically reformat the entered text into:
(333) 484-2989.

Could someone point me in the right direction as to how I
can do this? I already have a control like this for
datetime values, and that is easy because I just specify
to the control the formatting expression to pass to the
DateTime.tostring(format) mathod to re-format the entered-
in value. Now I just need to do this for a string based
input variable.

What's exactly the problem? You can trap the control's 'Validating'
event and do formatting there. Or you can use this control:

FlexMaskEditBox - a masked edit control
<http://www.codeproject.com/vb/net/cpflexmaskeditbox.asp>
 
I understand you talk about the actual formating technique.
in that case you might want to consider using regular expressions with a
replace method (System.Text.RegularExpressions.Regex class)

Picho
 
Back
Top