added new exercices
This commit is contained in:
1 parent
6b25e67c49
commit
c17800f71a
4 files changed
+96
No files matched your search
@@ -0,0 +1,25 @@
|
|||||||
|
using Algorithms.IdCard;
|
||||||
|
|
||||||
|
public class IDCard
|
||||||
|
{
|
||||||
|
private Name name;
|
||||||
|
private PostalCode postalCode;
|
||||||
|
private TelephonNumber telephonNumber;
|
||||||
|
|
||||||
|
public IDCard(Name name,
|
||||||
|
PostalCode postalCode,
|
||||||
|
TelephonNumber telephonNumber)
|
||||||
|
{
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
this.postalCode = postalCode;
|
||||||
|
this.telephonNumber = telephonNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsValid()
|
||||||
|
{
|
||||||
|
return name.IsValid()
|
||||||
|
&& telephonNumber.IsValid()
|
||||||
|
&& postalCode.IsValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
namespace Algorithms.IdCard;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class Name
|
||||||
|
{
|
||||||
|
private string firstName;
|
||||||
|
private string lastName;
|
||||||
|
|
||||||
|
public Name(string firstName, string lastName)
|
||||||
|
{
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool constainsNumber(string word){
|
||||||
|
string digits = "0123456789";
|
||||||
|
foreach (char digit in digits){
|
||||||
|
if(word.IndexOf(digit) != -1){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsValid(){
|
||||||
|
if(constainsNumber(this.firstName) || constainsNumber(this.lastName)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.firstName.Length > 1 && this.lastName.Length > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Algorithms.IdCard;
|
||||||
|
|
||||||
|
public class PostalCode
|
||||||
|
{
|
||||||
|
private string postalCode;
|
||||||
|
public PostalCode(string postalCode)
|
||||||
|
{
|
||||||
|
this.postalCode = postalCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsValid(){
|
||||||
|
Regex rx = new Regex(@"^[A-Z]\d[A-Z] \d[A-Z]\d$");
|
||||||
|
return rx.Match(this.postalCode).Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Algorithms.IdCard;
|
||||||
|
|
||||||
|
public class TelephonNumber
|
||||||
|
{
|
||||||
|
private string telephonNumber;
|
||||||
|
|
||||||
|
public TelephonNumber(string telephonNumber)
|
||||||
|
{
|
||||||
|
this.telephonNumber = telephonNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsValid(){
|
||||||
|
Regex rx = new Regex(@"^(\+?1 )?\d{3} \d{3}-\d{4}$");
|
||||||
|
return rx.Match(this.telephonNumber).Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user