13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

230<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>The first important feature to note is the regular expression that Visual Studio 2008generates:"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"If you spent several hours studying regular expressions, you could probably <strong>com</strong>e up withthe same expression. However, while learning <strong>ASP</strong>.<strong>NET</strong> and the associated C#, you haveyour hands full. Make a note to learn regular expressions later.When you test your application, enter an email without the @ sign. When you clickthe Send Information button, you will see a dramatically different error warning thanwe’ve used up to this point as shown in Figure 9-7. Not only does it sound like whatan alien <strong>com</strong>puter might <strong>com</strong>pose, the text is in a maroon monospaced font with yellowbacking.You also can leave out a domain (.net) or an initial identifier (billz), and the regularexpression will catch it and throw an error. Figure 9-8 shows what you will see when youget it right.Note the amount of space above the Email Address label. Even though the error messagedid not fire because no errors were detected, that space is still part of the RegularExpressionValidator. As a result, you have to carefully plan your data entry design so that your page isnot full of gaps where verbose error messages are meant to appear.Appreciating Regular ExpressionsIf you are doing a lot of database development with <strong>ASP</strong>.<strong>NET</strong> and C#, you might wantto consider investing some time learning regular expressions. The Regular ExpressionEditor only has 14 regular expressions, but you will find it uses far beyond those 14.You can configure very sophisticated regular expressions to get exactly what you wantfrom a database table, or you can add to a validation control. If you know any Perlprogrammers, they live and breathe regular expressions and will readily lead you tothe best learning materials on the topic. For a good quick start, check out <strong>www</strong>.regularexpressions.info/quickstart.html.You can find a nice regular expression “cheat sheet” at<strong>www</strong>.ilovejackdaniels.<strong>com</strong>/regular_expressions_cheat_sheet.pdf.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!