Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Entity Framework Core 2.0

You're reading from   Mastering Entity Framework Core 2.0 Dive into entities, relationships, querying, performance optimization, and more, to learn efficient data-driven development

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788294133
Length 386 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Prabhakaran Anbazhagan Prabhakaran Anbazhagan
Author Profile Icon Prabhakaran Anbazhagan
Prabhakaran Anbazhagan
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Kickstart - Introduction to Entity Framework Core 2. The Other Way Around – Database First Approach FREE CHAPTER 3. Relationships – Terminology and Conventions 4. Building Relationships – Understanding Mapping 5. Know the Validation – Explore Inbuilt Validations 6. Save Yourself – Hack Proof Your Entities 7. Going Raw – Leveraging SQL Queries in LINQ 8. Query Is All We Need – Query Object Pattern 9. Fail Safe Mechanism – Transactions 10. Make It Real – Handling Concurrencies 11. Performance – It's All About Execution Time 12. Isolation – Building a Multi-Tenant Database

RegularExpression field validation


Regular expression validation is the only solution used for most validations such as email, phone number, zip code, username, password, and so on. Most of the patterns used with regular expressions are wrapped into separate validations. Still, the usage is vast and requires a method to define custom validation. That's where RegularExpression validation comes in handy.  Lets investigate regular expressions in this section.

If the field value doesn't follow the defined regular expression pattern, then a validation error would be returned by the engine. For instance, if the regular expression is configured to contain only letters of the alphabet, then any other character inclusion would throw a validation error.

The RegularExpression attribute/data annotation can be configured as follows:

    public class Person
    {
      public int Id { get; set; }
      [Required(ErrorMessage = "First Name is required")]
      [RegularExpression("^[a-zA-Z]+$")]
      public...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime