How to Validate Forms with ASP.NET MVC 2 Data Annotations: Listing 2.

Customer Fields Modified with the Standard Data Annotation Validators

Imports System.ComponentModel
Imports System.ComponentModel.DataAnnotations

<MetadataType(GetType(CustomerMetaData))>
Partial Public Class Customer
End Class

Public Class CustomerMetaData
    <Required(ErrorMessage:="Name is Required")>
    <StringLength(25)>
    <RegularExpression("^[A-Za-z\-\.\' ]+$",
        ErrorMessage:=
          "Only letters, hyphen, apostrophe and period are allowed")>
    Public Property Name As Object
	
    <StringLength(50, ErrorMessage:=
      "Email Must Be No Longer than 50 Characters")>
    Public Property Email As Object
	
    <Range(100, 1000)>
    Public Property CreditLimit As Object

        <DisplayName("Anniversary Date")>
        <Required()>
        <Range(GetType(DateTime), "01/01/2000", "12/31/2010")>
        <DisplayFormat(DataFormatString:="{0:d}", 
          ApplyFormatInEditMode:=True)>
        Public Property AnniversaryDate As Object

End Class
comments powered by Disqus

Featured

  • Microsoft's New Programming Language for Excel Now Turing Complete

    Microsoft, which calls its Excel spreadsheet a programming language, reports that an effort called LAMBDA to make it even more of a programming language is paying off, recently being deemed Turing complete.

  • New Visual Studio Razor Editor 'Close to Being Ready' for Blazor and Other Projects

    The experimental Razor editor for Visual Studio introduced last summer has been updated and is "close to being ready for normal daily development."

  • Microsoft Updates 'Must Have' Xamarin Community Toolkit

    The Xamarin Community Toolkit provides all kinds of effects, views and helpers to complement mobile app development with Microsoft's recently released, open source, cross-platform Xamarin.Forms 5.

  • JetBrains Unveils Plans for WinForms, WPF and More in Rider .NET IDE

    JetBrains announced plans for Windows Forms, Windows Presentation Foundation (WPF), ASP.NET and more tooling in the next release of its popular Rider IDE for .NET development.

Upcoming Events