Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Getting Started with Regular Expressions : Page 4

Regular expressions, also referred to as "regex" in the developer community, are extremely powerful pattern matching and substitution tools. This article introduces you to regular expressions, what they are, why you would want to use them, and finally, how you can begin putting them to work in Visual Studio .NET.




Application Security Testing: An Integral Part of DevOps

Figure 1: The properties for the regPhoneNumber RegularExpressionValidator control.
Using Regular Expressions in Visual Studio .NET
Now that you've seen the fundamentals of building a regular expression pattern, and you've reviewed a number of popular patterns, it's time to find out how to implement a regular expression in Visual Studio .NET.

Visual Studio .NET supports regular expressions in ASP.NET via the RegularExpressionValidator control and in code via the RegEx class.

While there is more than one way to use regular expressions in ASP.NET, the most common is to use the RegularExpressionValidator control.

A developer uses the RegularExpressionValidator control to make sure the entry in a watched control conforms to a specified regular expression. This allows you to check an entry against a pattern such as a U.S. Social Security number, telephone number, e-mail address, etc.

The following snippet lists the HTML for a RegularExpressionValidator control watching over a textbox containing U.S. phone number information.

            "Please enter a valid phone number!" 
            "((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">
The Property window in Figure 1 shows the regPhoneNumber Control.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date