The CharacterValidator determines if your textbox has text where every character
is in a character set that you specify. It doesn’t define a pattern or order to
the characters. Patterns, like phone numbers or addresses, need the power of the
RegexValidator. Some examples where a limited character set applies:
- Passwords – perhaps you only allow letters, digits, space and underscore
- Credit card numbers – only allow digits
- Person’s first name – only allow letters
When used with the FilteredTextBox, it automatically uses the FilteredTextBox’s
properties to define the character set. It ignores properties that define the character
set on itself.
Specify the control to evaluate with the ControlIDToEvaluate property.
Use these Boolean properties to determine the set of characters: LettersUppercase,
LettersLowercase, DiacriticLetters, Digits, Space, Enter,
Punctuation, CurrencySymbols, EnclosureSymbols, MathSymbols,
and VariousSymbols. For any other characters or to define a subset of the
predefined character definitions, use the OtherCharacters property to list
the characters you want.
If you want all characters except a specific character set, define the character
set using the preceding properties and set the property Exclude to true.
Limited to digits and letters. (Paste can bypass the FilteredTextBox filtering.)
Limited to digits and letters. The Textbox itself has no filters, so it allows all characters.
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (PeterBlum.DES.Globals.WebFormDirector.IsValid)
{
}
}
</script>
<h2>FilteredTextBox</h2>
Limited to digits and letters. (Paste can bypass the FilteredTextBox filtering.)<br/>
<des:FilteredTextBox ID="TextBox1" runat="server" Digits="true" LettersLowercase="true"
LettersUppercase="true" />
<des:CharacterValidator ID="CharacterValidator1" runat="server" ControlIDToEvaluate="TextBox1"
ErrorMessage="Illegal characters." />
<br/>
<h2>TextBox</h2>
Limited to digits and letters. The Textbox itself has no filters, so it allows all characters.<br/>
<des:TextBox ID="TextBox2" runat="server" />
<des:CharacterValidator ID="CharacterValidator2" runat="server"
ControlIDToEvaluate="TextBox2"
ErrorMessage="Illegal characters."
Digits="true" LettersLowercase="true" />
<br/>
<br/>
<des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>