All Validation.
Create class Customer with following member
Id
UserId : Minimum 5 character and maximum 15 character allowed
Name: Minimum 3 character required
Password: Minimum 8 character required
Photo: store imahe path Image/a.png
URL: it will display Http://www.myblog,com
Address: it is text area minimum 15 character required
Pincode: it has exact 6 digit
Mobile: it has exact 10 digit
DOB: it should display calander and store date dd/mm/yyyy
Email: email of customer
Confirm Email: it should match email column
Gender: dropdown.
Creditscore: any value between 1 to 10 allowed.
Create strongly type view and perform all validation.
Complete CRUD operation for
SOLUTION:-
Step- Create empty mvc app, add control with select 3rd option (crud option),
step- Select db 1st apporoach due to already grenerate db by model first approach in another app thats y we choose this option, build app,
step- create model_Mapper.cs file for map validation.
CustomerMapper
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace MVC_Validation_Crud.Models
{
[MetadataType(typeof(CustomerMapper))]
public partial class Customer
{
}
public class CustomerMapper
{
[Key]
public int Id { get; set; }
[Required]
[StringLength(15, MinimumLength = 3)]
[DisplayName("Customer Name")]
public string Name { get; set; }
[Required]
[StringLength(15, MinimumLength = 8)]
[DataType(DataType.Password)]
public string Password { get; set; }
[Required]
[DataType(DataType.MultilineText)]
public string Address { get; set; }
[Required]
[DataType(DataType.Date)] //input type="Date [Calander]
[DisplayFormat(DataFormatString = "{0:d}",
ApplyFormatInEditMode = true)]
public System.DateTime DOB {
get; set; }
[Required]
public int Age { get; set; }
[Required]
public string Photo { get; set; }
[Required(ErrorMessage = "Please enter your URL correctly")]
[DataType(DataType.Url)] // a href="Http...."
public string URL { get; set; }
[Required]
[DataType(DataType.EmailAddress)] //input type ="Email"
[RegularExpression(@"^[\w-\._\+%]+@(?:[\w-]+\.)+[\w]{2,6}$", ErrorMessage = "Please enter a
valid email address")]
public string Email { get; set; }
[Compare("Email", ErrorMessage = "Email and confirm Email should
match")]
public string Cmail { get; set; }
[RegularExpression("[0-9]{10}", ErrorMessage = "Please enter a
valid mobile address")]
[Required(ErrorMessage = "Please enter your phone number")]
[DataType(DataType.PhoneNumber)] //type="tel
public string Mobile { get; set; }
[Required]
public string Gender { get; set; }
[Required]
public bool Remember { get; set; }
[RegularExpression("[0-9]{6}", ErrorMessage = "Please enter a
valid Postal Code")]
[Required(ErrorMessage = "Please enter your Pin code")]
public string Pincode { get; set; }
}
}
No comments: