Mask for text boxes

J

John

Hi

I am using text boxes on a web form. How can I make it so users can insert
values only in the format 99-99-99 ?

Thanks

Regards
 
N

Nathan Sokalski

Try using the RegularExpressionValidator, which will validate the user's
input. If you want to restrict the characters that the user can type, you
can use JavaScript (there is a function I wrote that adds this JavaScript if
you would like me to send it to you). You can also use something from the
ASP.NET AJAX Control Toolkit called MaskedEdit, which you can see a
demonstration of at:

http://ajax.asp.net/ajaxtoolkit/MaskedEdit/MaskedEdit.aspx

However, if you do not have the ASP.NET AJAX Control Toolkit already
installed, that may be more work than it's worth (my function is much
simpler, and you do not need to install anything or change any configuration
settings, but is not as fancy). Hopefully one of these options is what you
are looking for, or at least helps you find a solution. Good Luck!
 
R

Rich

Checked out that Masked Edit Control, looks good, but WHY part of the AJAX
toolkit.

Is it doing ANYTHING that is asynchronous? Surely this can be implemented
completely client side with Javascript.

I suppose this control collection is MUCH more up to date and where all the
work is happening.

Just seems a bit weird...
 
N

Nathan Sokalski

Well, since I didn't write the controls I can't answer that for sure, but
there is a way to download the source code that was used to write them (it
is C# code). I am guessing, however, that the AJAX part is because of the
watermark (like the TextBoxWatermark control located at
http://ajax.asp.net/ajaxtoolkit/TextBoxWatermark/TextBoxWatermark.aspx). Or
it might just be to simplify the coding, I haven't looked at the source
code. But I agree with you, it probably is possible to get the same (or at
least close to) the same results without using AJAX.
 
J

John

I am trying to use RegularExpressionValidator as it seems to be easiest to
me. What expression do I need for the following type of values;

A9 9AA
A99 9AA
A9A 9AA
AA9 9AA
AA99 9AA
AA9A 9AA

and

99-99-99

A= Alphabets (A-Z, a-z)
9 = digits (0-9)

Many Thanks

Regards
 
N

Nathan Sokalski

Try taking a look at the following .NET documentation page:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/0f8bffab-ee0d-4e0e-9a96-2b4a252bb7e4.htm

You probably want the following expression:

"\d\d-\d\d-\d\d"

However, take note that in this expression there MUST be a digit for \d. If
you want to make a \d optional, add a ? after it, as in the following:

"\d?\d-\d?\d-\d?\d" (this expression would match 1-1-1 or 12-12-12)

For more information on the ? see the following documentation page:

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/36b81212-6511-49ed-a8f1-ff080415312f.htm

Hopefully this will help you get started. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top