-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreditCardValidator.cs
41 lines (38 loc) · 1.19 KB
/
CreditCardValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Entities.Concrete;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Business.ValidationRules.FluentValidation
{
class CreditCardValidator:AbstractValidator<CreditCard>
{
public CreditCardValidator()
{
RuleFor(c => c.Cvv).Length(3);
RuleFor(c => c.CardNo).Length(12);
RuleFor(c => c.SonKullanim).Must(SonKullanimKontrol).WithMessage("Son kullanım tarih formatını kontrol ediniz. mm/yyyy şeklinde olmalı");
}
private bool SonKullanimKontrol(string sonKullanim)
{
try
{
if (sonKullanim.Length == 7)
{
int ay = Convert.ToInt32(sonKullanim.Substring(0, 2));
int yil = Convert.ToInt32(sonKullanim.Substring(3, 4));
string slash = sonKullanim.Substring(2, 1);
if ((ay > 0 && ay <= 12) && slash == "/")
{
return true;
}
}
}
catch
{
return false;
}
return false;
}
}
}