.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Regular Expression Validation In Silverlight

Posted By:Diptimaya Patra       Posted Date: March 24, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Regular Expression Validation In Silverlight. In this article we will see how we can use RegEx Validation in Silverlight.


In this article we will see how we can use RegEx Validation in Silverlight.

Creating Silverlight Project

Fire up Visual Studio 2008 and create a new Silverlight 3 Project. Name it as RegExValidation.

The sample application will contain two TextBox. In one TextBox we will input the RegEx Expression and in the other we will input a value matching to it. If both matches display success message if not display error message.

Remember we can only validate the RegEx expression with a matching value only. We cannot validate a RegEx expression (till now).

Create two TextBoxes with a Button and a Status TextBlock.

You need to use the following Namespace to use RegEx.

using System.Text.RegularExpressions;
In the Button click event check whether the value matches.

private void btnCheck_Click(object sender, RoutedEventArgs e)
  string pattern = txtRegEx.Text;
  string content = txtDefaultValue.Text;
  if (Regex.IsMatch(content,pattern))
 txtStatus.Text = "Regular Expression and Default Value are Matched";
 txtStatus.Text = "Regular Expression or Default Value is Wrong";

That's it. It's so simple. Now if you run the application, you can check whether your RegEx expression is matching to default value or not.

Hope this article helps.
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend