Skip to main content

Microsoft Silverlight

Answered Question Format and validation in a textbox?RSS Feed

(0)

karlssonkatrin
karlsson...

Member

Member

1 points

73 Posts

Format and validation in a textbox?

Is there any way to set format and validation on a TextBox, for example:

111111-1111

it should be possible for the user to add 10 digits, the - should appear automatically in a position.

Is this possible, and in that case how?

 

varshavmane
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Re: Format and validation in a textbox?

Hello,

Hope this helps you :

void txt_TextChanged(object sender, TextChangedEventArgs e)

{

if (txt.Text.Length == 6)txt.Text += "-";

}

void txt_KeyDown(object sender, KeyEventArgs e)

{

if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Subtract || (e.Key >= Key.D0 && e.Key <= Key.D9))

e.Handled = false;

else

{

e.Handled =
true;

}

}

 

And Set txt.MaxLength = 10;

HTH Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

karlssonkatrin
karlsson...

Member

Member

1 points

73 Posts

Re: Re: Format and validation in a textbox?

Hi

I need to have this customized, for example different formats for zipcode in different countries. So I need to fetch it freom a .resx file or from configuration, I'm not able to 'hardcode' it.

Is there support for masks?

Regards Katrin

varshavmane
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Answered Question

Re: Re: Re: Format and validation in a textbox?

I dont think so but you can try creating Silverlight Class Library for the same and take the reference of it in your Silverlight Project.

HTH Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities