开发者

Getting Literal Value from a Masked Text Box Input

开发者 https://www.devze.com 2023-03-25 03:13 出处:网络
I\'ve set up a Telerik RadMaskedTextBox with a Mask of \"####-####\". The problem is, when I later grab the value from this box it returns as \"########\". I\'m unfamiliar with MaskedTextBoxes but I\'

I've set up a Telerik RadMaskedTextBox with a Mask of "####-####". The problem is, when I later grab the value from this box it returns as "########". I'm unfamiliar with MaskedTextBoxes but I'm guessing that this is the default way it's supposed to return my value.

How can I set the "-" as a literal character in the R开发者_如何转开发adMaskedTextBox so it returns the whole value?

ex. "1234-5678" instead of "12345678"


Use TextWithLiterals instead of Text property.


I'm unfamiliar with the Telerik controls, but you know the mask and you know the value you're getting, so you can construct the formatted value yourself:

var val = control.Text;
var mask = control.Mask;
var v = 0;
var builder = new StringBuilder();

foreach(var c in mask)
   builder.Append(c == '#' ? val[v++] : c);

return builder.ToString();
0

精彩评论

暂无评论...
验证码 换一张
取 消