Implementing Syncfusion WPF MaskedTextBox (SfMaskedEdit)
The WPF MaskedTextBox (SfMaskedEdit) is an advanced input control that restricts user input to specific types using mask patterns. It's ideal for creating templates for phone numbers, IP addresses, product IDs, dates, and other formatted data entry.
When to Use This Skill
Use this skill when you need to:
- Restrict input to specific formats without custom validation
- Implement formatted input fields for phone numbers, emails, dates, currency
- Create mask patterns using Simple or RegEx mask types
- Validate user input on key press or lost focus
- Format values with or without literals and prompt characters
- Display error indicators for invalid input
- Add watermarks to guide user input
- Customize appearance including colors, borders, and themes
- Support RTL layouts for international applications
- Handle value changes with event notifications
Component Overview
SfMaskedEdit provides:
- Multiple mask types: Simple and RegEx patterns
- Flexible validation: KeyPress or LostFocus validation modes
- Value formatting: Include/exclude prompts and literals
- Visual feedback: Error borders, prompt characters, watermarks
- Full customization: Colors, themes, templates
- MVVM support: Data binding and property change notifications
Assembly: Syncfusion.SfInput.WPF, Syncfusion.SfShared.WPF
Namespace: Syncfusion.Windows.Controls.Input
Documentation and Navigation Guide
Getting Started
📄 Read: references/getting-started.md
- Assembly deployment and NuGet installation
- Adding SfMaskedEdit via designer, XAML, and C#
- Basic configuration and setup
- First masked textbox example
- Handling ValueChanged events
Mask Patterns and Input Restriction
📄 Read: references/mask-patterns-input-restriction.md, references/mask-patterns-advanced.md
- Mask element reference ([], \d, \w, {n}, +, *, ?, etc.)
- Creating custom mask patterns
- Allow/restrict specific values with (?=) and (?!)
- Extensive mask examples (phone, email, currency, dates, etc.)
- Input validation modes (KeyPress vs LostFocus)
- Validation results and HasError property
- PromptChar and ShowPromptOnFocus configuration
Value Management
📄 Read: references/value-management.md, references/value-management-advanced.md
- Setting and getting Value property
- ValueMaskFormat options:
- ExcludePromptAndLiterals
- IncludeLiterals
- IncludePrompt
- IncludePromptAndLiterals
- Value change notifications
- Clipboard operations with formatted values
Appearance and Customization
📄 Read: references/appearance-customization.md, references/appearance-customization-themes.md
- Background, Foreground, and SelectionBrush
- CaretBrush and BorderBrush customization
- ErrorBorderBrush for validation feedback
- FlowDirection for RTL support
- Watermark and WatermarkTemplate
- Theme integration and styling
Quick Start Example
Phone Number Mask
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<syncfusion:SfMaskedEdit
x:Name="phoneNumber"
Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}"
MaskType="RegEx"
Value="4553456789"
PromptChar="_"
Width="200"
Height="30"
ValueChanged="PhoneNumber_ValueChanged"/>
</Grid>
</Window>
using Syncfusion.Windows.Controls.Input;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void PhoneNumber_ValueChanged(object sender, EventArgs e)
{
var maskedEdit = sender as SfMaskedEdit;
if (!maskedEdit.HasError)
{
// Use formatted value: (455) 345-6789
string formattedPhone = maskedEdit.Value;
}
}
}
Common Patterns
Key patterns include Email, Currency, Date, Product Key, and Value Formatting. See Mask Patterns and Input Restriction for 25+ detailed pattern examples with complete XAML and code samples.
Key Properties
Essential properties include Mask (pattern), MaskType (Simple/RegEx), Value (formatted output), ValueMaskFormat (format control), ValidationMode (KeyPress/LostFocus), HasError (validation status), PromptChar (missing input indicator), ErrorBorderBrush (error feedback), and Watermark (placeholder text). See Getting Started and Mask Patterns for property details and 25+ mask pattern examples.
Common Use Cases
- Data Entry Forms: Contact info, financial data, ID numbers with automatic formatting
- Phone/Finance: Consistent formatting across app, currency/percent enforcement
- Product Registration: Validate product keys and serial numbers
- Date/Time: Custom formats beyond DatePicker with RegEx validation
- International: RTL support via FlowDirection, regional date/phone formats
- Real-time Validation: KeyPress for instant feedback or LostFocus for less intrusive
Events
| Event |
Description |
| ValueChanged |
Fires when Value property changes (based on ValidationMode) |
| LostFocus |
Standard WPF event, useful with LostFocus validation mode |
Best Practices
- Choose appropriate MaskType: Use RegEx for complex patterns, Simple for basic scenarios
- Set ValueMaskFormat early: Determine format before accessing Value property
- Provide visual feedback: Use ErrorBorderBrush and Watermark for better UX
- Match validation mode to UX: KeyPress for instant feedback, LostFocus for less intrusive validation
- Document custom patterns: Comment complex RegEx masks for maintainability
- Test edge cases: Verify behavior with empty input, partial input, and boundary values
- Use ShowPromptOnFocus: Enable for better visibility of expected input format
Next Steps: Choose a reference file above based on your needs, or start with getting-started.md for initial setup.
1---2name: syncfusion-wpf-maskedtextbox3description: Comprehensive guide for implementing Syncfusion WPF MaskedTextBox (SfMaskedEdit) control for restricted input with mask patterns. Use this skill when implementing masked input, input masks, or input restrictions with predefined patterns in WPF. Covers phone number input, email validation, credit card input, formatted input with prompt characters, RegEx masks, and custom patterns for dates, currency, product keys, and zip codes.4---56# Implementing Syncfusion WPF MaskedTextBox (SfMaskedEdit)78The WPF MaskedTextBox (SfMaskedEdit) is an advanced input control that restricts user input to specific types using mask patterns. It's ideal for creating templates for phone numbers, IP addresses, product IDs, dates, and other formatted data entry.910## When to Use This Skill1112Use this skill when you need to:13- **Restrict input to specific formats** without custom validation14- **Implement formatted input fields** for phone numbers, emails, dates, currency15- **Create mask patterns** using Simple or RegEx mask types16- **Validate user input** on key press or lost focus17- **Format values** with or without literals and prompt characters18- **Display error indicators** for invalid input19- **Add watermarks** to guide user input20- **Customize appearance** including colors, borders, and themes21- **Support RTL layouts** for international applications22- **Handle value changes** with event notifications2324## Component Overview2526**SfMaskedEdit** provides:27- **Multiple mask types:** Simple and RegEx patterns28- **Flexible validation:** KeyPress or LostFocus validation modes29- **Value formatting:** Include/exclude prompts and literals30- **Visual feedback:** Error borders, prompt characters, watermarks31- **Full customization:** Colors, themes, templates32- **MVVM support:** Data binding and property change notifications3334**Assembly:** `Syncfusion.SfInput.WPF`, `Syncfusion.SfShared.WPF` 35**Namespace:** `Syncfusion.Windows.Controls.Input`3637## Documentation and Navigation Guide3839### Getting Started40📄 **Read:** [references/getting-started.md](references/getting-started.md)41- Assembly deployment and NuGet installation42- Adding SfMaskedEdit via designer, XAML, and C#43- Basic configuration and setup44- First masked textbox example45- Handling ValueChanged events4647### Mask Patterns and Input Restriction48📄 **Read:** [references/mask-patterns-input-restriction.md](references/mask-patterns-input-restriction.md), [references/mask-patterns-advanced.md](references/mask-patterns-advanced.md)49- Mask element reference ([], \d, \w, {n}, +, *, ?, etc.)50- Creating custom mask patterns51- Allow/restrict specific values with (?=) and (?!)52- Extensive mask examples (phone, email, currency, dates, etc.)53- Input validation modes (KeyPress vs LostFocus)54- Validation results and HasError property55- PromptChar and ShowPromptOnFocus configuration5657### Value Management58📄 **Read:** [references/value-management.md](references/value-management.md), [references/value-management-advanced.md](references/value-management-advanced.md)59- Setting and getting Value property60- ValueMaskFormat options:61 - ExcludePromptAndLiterals62 - IncludeLiterals63 - IncludePrompt64 - IncludePromptAndLiterals65- Value change notifications66- Clipboard operations with formatted values6768### Appearance and Customization69📄 **Read:** [references/appearance-customization.md](references/appearance-customization.md), [references/appearance-customization-themes.md](references/appearance-customization-themes.md)70- Background, Foreground, and SelectionBrush71- CaretBrush and BorderBrush customization72- ErrorBorderBrush for validation feedback73- FlowDirection for RTL support74- Watermark and WatermarkTemplate75- Theme integration and styling7677## Quick Start Example7879### Phone Number Mask8081```xml82<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"83 xmlns:syncfusion="http://schemas.syncfusion.com/wpf"84 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">85 <Grid>86 <syncfusion:SfMaskedEdit 87 x:Name="phoneNumber"88 Mask="\([0-9]\d{2}\) [0-9]\d{2}-[0-9]\d{3}" 89 MaskType="RegEx"90 Value="4553456789"91 PromptChar="_"92 Width="200" 93 Height="30"94 ValueChanged="PhoneNumber_ValueChanged"/>95 </Grid>96</Window>97```9899```csharp100using Syncfusion.Windows.Controls.Input;101102public partial class MainWindow : Window103{104 public MainWindow()105 {106 InitializeComponent();107 }108109 private void PhoneNumber_ValueChanged(object sender, EventArgs e)110 {111 var maskedEdit = sender as SfMaskedEdit;112 if (!maskedEdit.HasError)113 {114 // Use formatted value: (455) 345-6789115 string formattedPhone = maskedEdit.Value;116 }117 }118}119```120121## Common Patterns122123Key patterns include Email, Currency, Date, Product Key, and Value Formatting. See [Mask Patterns and Input Restriction](references/mask-patterns-input-restriction.md) for 25+ detailed pattern examples with complete XAML and code samples.124125## Key Properties126127Essential properties include **Mask** (pattern), **MaskType** (Simple/RegEx), **Value** (formatted output), **ValueMaskFormat** (format control), **ValidationMode** (KeyPress/LostFocus), **HasError** (validation status), **PromptChar** (missing input indicator), **ErrorBorderBrush** (error feedback), and **Watermark** (placeholder text). See [Getting Started](references/getting-started.md) and [Mask Patterns](references/mask-patterns-input-restriction.md) for property details and 25+ mask pattern examples.128129## Common Use Cases130131- **Data Entry Forms:** Contact info, financial data, ID numbers with automatic formatting132- **Phone/Finance:** Consistent formatting across app, currency/percent enforcement133- **Product Registration:** Validate product keys and serial numbers134- **Date/Time:** Custom formats beyond DatePicker with RegEx validation135- **International:** RTL support via FlowDirection, regional date/phone formats136- **Real-time Validation:** KeyPress for instant feedback or LostFocus for less intrusive137138## Events139140| Event | Description |141|-------|-------------|142| **ValueChanged** | Fires when Value property changes (based on ValidationMode) |143| **LostFocus** | Standard WPF event, useful with LostFocus validation mode |144145## Best Practices1461471. **Choose appropriate MaskType:** Use RegEx for complex patterns, Simple for basic scenarios1482. **Set ValueMaskFormat early:** Determine format before accessing Value property1493. **Provide visual feedback:** Use ErrorBorderBrush and Watermark for better UX1504. **Match validation mode to UX:** KeyPress for instant feedback, LostFocus for less intrusive validation1515. **Document custom patterns:** Comment complex RegEx masks for maintainability1526. **Test edge cases:** Verify behavior with empty input, partial input, and boundary values1537. **Use ShowPromptOnFocus:** Enable for better visibility of expected input format154155---156157**Next Steps:** Choose a reference file above based on your needs, or start with getting-started.md for initial setup.