Demo: FilteredTextBox Control
Back
The FilteredTextBox provides client-side filtering of keystrokes based on the set
of characters that you specify. You set properties to quickly define your characterset:
- Digits
- Uppercase letters
- Lowercase letters
- Space
- Enter (on multiline textboxes)
- These predefined charactersets: DiacriticLetters, Punctuation, EnclosureSymbols,
MathSymbols, CurrencySymbols, and VariousSymbols
- Other characters - define any character you want into a string
- Exclude - when set, the character set defined is invalid and all other characters
are valid.
When a CharacterValidator is connected to this textbox, additional validation occurs
when javascript is disabled on the browser. The CharacterValidator automatically
configures itself to the characterset properties on the FilteredTextBox.
The FilteredTextBox does not care about the position of each character, like a masked
textbox would. However, you can use it with a RegexValidator to validate that the
entry matches a desired pattern.
The FilteredTextBox is based on DES's TextBox control, inheriting its rich feature
set and that of its ancestor, Microsoft's TextBox. You can quickly swap it for Microsoft's
TextBox without changing your code. All you need to do is:
- Change the ASP.NET text tag <asp:TextBox> to <des:FilteredTextBox>.
- In the code behind file, change the class of the control from System.Web.UI.WebControls.TextBox
to PeterBlum.DES.Web.WebControls.FilteredTextBox.
- Set the characterset properties.
- Add the CharacterValidator.
Demo 1 - Password
This textbox is used for a password. It is limited to all letters, digits and underscore.
Type anything you like:
ASP.NET Syntax for this demo
<des:FilteredTextBox id="FilteredTextBox1" runat="server"
LettersLowercase="True" LettersUppercase="True" Digits="True" OtherCharacters="_" />
Demo 2 - Social Security Number
This textbox is used for a U.S. Social Security Number. It has the format of ###-##-####
where # is for a digit. In this demo, a RegexValidator is used to confirm that pattern.
(The RegexValidator's Property Editor provides the regular expression for social
security numbers.)
Type anything you like:
The pattern must be ###-##-####
ASP.NET Syntax for this demo
<des:FilteredTextBox ID="FilteredTextBox2" runat="server" Digits="True" OtherCharacters="-" />
<des:RegexValidator ID="RegexValidator1" runat="server"
ControlIDToEvaluate="FilteredTextBox2"
ErrorMessage="The pattern must be ###-##-####"
Expression="^\d{3}-\d{2}-\d{4}$" />
Back