Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>couple months ago I <a href="http://outcoldman.ru/en/blog/show/308" rel="nofollow">wrote a blog</a> post about Behaviors for TextBox (Windows Phone 7.5 platform), and one of these bahaviors was the TextBoxInputRegexFilterBehavior, which allows you to filter input text. So if you are familar with how Behaviors work you can use this code</p> <pre><code>using System.Text.RegularExpressions; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Interactivity; /// &lt;summary&gt; /// UI behavior for &lt;see cref="TextBox"/&gt; to filter input text with special RegularExpression. /// &lt;/summary&gt; public class TextBoxInputRegexFilterBehavior : Behavior&lt;TextBox&gt; { private Regex regex; private string originalText; private int originalSelectionStart; private int originalSelectionLength; /// &lt;summary&gt; /// Gets or sets RegularExpression. /// &lt;/summary&gt; public string RegularExpression { get { return this.regex.ToString(); } set { if (string.IsNullOrEmpty(value)) { this.regex = null; } else { this.regex = new Regex(value); } } } /// &lt;inheritdoc/&gt; protected override void OnAttached() { base.OnAttached(); this.AssociatedObject.TextInputStart += this.AssociatedObjectTextInputStart; this.AssociatedObject.TextChanged += this.AssociatedObjectTextChanged; } /// &lt;inheritdoc/&gt; protected override void OnDetaching() { base.OnDetaching(); this.AssociatedObject.TextInputStart -= this.AssociatedObjectTextInputStart; this.AssociatedObject.TextChanged -= this.AssociatedObjectTextChanged; } private void AssociatedObjectTextChanged(object sender, TextChangedEventArgs e) { if (this.originalText != null) { string text = this.originalText; this.originalText = null; this.AssociatedObject.Text = text; this.AssociatedObject.Select(this.originalSelectionStart, this.originalSelectionLength); } } private void AssociatedObjectTextInputStart(object sender, TextCompositionEventArgs e) { if (this.regex != null &amp;&amp; e.Text != null &amp;&amp; !(e.Text.Length == 1 &amp;&amp; char.IsControl(e.Text[0]))) { if (!this.regex.IsMatch(e.Text)) { this.originalText = this.AssociatedObject.Text; this.originalSelectionStart = this.AssociatedObject.SelectionStart; this.originalSelectionLength = this.AssociatedObject.SelectionLength; } } } } </code></pre> <p>So, with this behavior you can write simple regex expression which will filter user input, like this RegularExpression="(3[0-5])|([0-2]?[0-9])"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload