TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vijay rags
NA
68
163.7k
How to validate textbox on key down event to accept only numbers in silverlight 4
Nov 19 2011 9:02 AM
Hi,
i need a validation to check whether key pressed down is numeric or not. i tried with different code but they cant help me out.In the textbox if the user press Shift+numbers it displays special charcters like !,@,#...... I need to validate the Shift + key down event. Please find the sample code i tried below and help me out.
private void
txtNumericTextbox_KeyDown
(object sender, KeyEventArgs e)
{
try
{
if (e.Key < Key.D0 || e.Key > Key.D9)
{
if (e.Key < Key.NumPad0 || e.Key > Key.NumPad9)
{
if (e.Key != Key.Back)
{
txtNumericTextbox_
.BorderBrush = new SolidColorBrush(Colors.Red);
lblErrorMessage.Visibility = Visibility.Visible;
lblErrorMessage.Text = "Please Enter Numbers Only";
}
else
{
txtNumericTextbox_
.BorderBrush = new SolidColorBrush(Colors.DarkGray);
lblErrorMessage.Visibility = Visibility.Collapsed;
lblErrorMessage.Text = "";
}
}
}
Thanks,
Vijay
Reply
Answers (
7
)
Tools
Communication in WCF