c# - MaskedTextBox Enforce UpperCase Characters -
i'm utilizing telerik's radmaskedtextbox , i'm trying create mask such it'll follow canadian postal code template.
template followed letter number letter number letter number
example postal code t4r1u8
at moment mask mask="l#l #l#"
allows both uppercase , lowercase letters. i'm trying have uppercase letters can inputted , lower case can inputted lower case change upper.
i've tried 2 solutions, close not quite final solution.
first 1 tackling on viewmodel side
public string postalcode { {return postalcode;} set { postalcode = value; postalcode = postalcode.toupper(); onpropertychanged("postalcode"); } }
this approach, values change upper typing index moves front of masktextbox instead of remaining after character typed.
the second approach took works doesn't allow me type lowercase characters. ended using customtoken. '*' custom token char new mask mask="*#* #*#"
public class customtoken : itokenvalidationrule { #region itokenvalidationrule members public bool isrequired { { return false; } } public bool isvalid(char ch) { return validchars.contains(ch); } public char token { { return '*'; } } public tokentypes type { { return tokentypes.alphanumeric; } } private string myvalidchars = "abcdefghijklmnopqrstuvwxyz"; public string validchars { { return myvalidchars; } } #endregion }
any tips appreciated.
there similar question here.
the solution use selectionstart set caret @ end, eg:
dispatcher.begininvoke(() => { if (txtpocode.maskedtext != null) { txtpocode.maskedtext = txtpocode.maskedtext.toupper(); txtpocode.selectionstart = txtpocode.maskedtext.length; txtpocode.focus(); } });
Comments
Post a Comment