Skip to content

Commit

Permalink
N191 is done
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 5, 2023
1 parent 1543272 commit 45663d7
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N18", "N18", "{0104B5A8-DF0
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N18_1", "N18_1", "{2D7CB3B4-5800-4F9D-B995-0989DC4898B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N18_1", "N18_1\N18_1.csproj", "{CDF49DFE-F765-4582-A415-7FCE7BB26FE6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N18_1", "N18_1\N18_1.csproj", "{CDF49DFE-F765-4582-A415-7FCE7BB26FE6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N19", "N19", "{5D0A5ACF-8665-4299-8A8E-D79498D3D059}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N19_1", "N19_1\N19_1.csproj", "{96392CE8-A652-4D1D-BD85-09B29E96B12C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -287,6 +291,10 @@ Global
{CDF49DFE-F765-4582-A415-7FCE7BB26FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDF49DFE-F765-4582-A415-7FCE7BB26FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDF49DFE-F765-4582-A415-7FCE7BB26FE6}.Release|Any CPU.Build.0 = Release|Any CPU
{96392CE8-A652-4D1D-BD85-09B29E96B12C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96392CE8-A652-4D1D-BD85-09B29E96B12C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96392CE8-A652-4D1D-BD85-09B29E96B12C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96392CE8-A652-4D1D-BD85-09B29E96B12C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -347,6 +355,7 @@ Global
{65E92671-E1EA-4796-8A1B-2D6A16C4CBDF} = {9B79AF1D-7835-40D1-9478-26BD79673DEA}
{2D7CB3B4-5800-4F9D-B995-0989DC4898B7} = {0104B5A8-DF02-4BC4-8E92-41F722E87720}
{CDF49DFE-F765-4582-A415-7FCE7BB26FE6} = {2D7CB3B4-5800-4F9D-B995-0989DC4898B7}
{96392CE8-A652-4D1D-BD85-09B29E96B12C} = {5D0A5ACF-8665-4299-8A8E-D79498D3D059}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
10 changes: 10 additions & 0 deletions N19_1/N19_1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
30 changes: 30 additions & 0 deletions N19_1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using N19_1;

//for name
if (Validator.IsValidName(" Abdurahmon ", out var formattedName))
Console.WriteLine($"fixed name - {formattedName}");
else
Console.WriteLine("Invalid name is not fixed");


// for email
if (Validator.IsValidEmailadress(" [email protected]", out var formattedEmailAddress))
Console.WriteLine($"true fixedEmailAddress - {formattedEmailAddress}");
else
Console.WriteLine("Invalid email is not fixed");

//for phone number
if (Validator.IsValidPhoneNumber(" +998938399777 ", out var formattedPhoneNumber))
Console.WriteLine($"true fixed Phone Number - {formattedPhoneNumber}");
else
Console.WriteLine("Invalid phone number is not fixed");


//for age
var age = Console.ReadLine();
if (Validator.IsValidAge(age))
Console.WriteLine($"valid age");
else
Console.WriteLine("Invalid invalid is not fixed");


66 changes: 66 additions & 0 deletions N19_1/Validator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace N19_1
{
public static class Validator
{
public static bool IsValidName(in string name, out string formattedName)
{
formattedName = string.Empty;
if(string.IsNullOrWhiteSpace(name)) return false;

formattedName = name.Trim();
if (Regex.IsMatch(formattedName, "^[A-Za-z][A-Za-z0-9]*$"))
return true;
return false;
}


public static bool IsValidEmailadress(in string emailAddress, out string formattedEmailAddress)
{
formattedEmailAddress = string.Empty;
if (string.IsNullOrWhiteSpace(emailAddress)) return false;

formattedEmailAddress = emailAddress.Trim();
return Regex.IsMatch(formattedEmailAddress, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$");
}


public static bool IsValidAge(in string age)
{
try
{

if (Convert.ToInt32(age) < 1)
{
return false;

}
else
{
return true;

}
}
catch
{
return false;
}
}

public static bool IsValidPhoneNumber(in string phoheNumber, out string formattedPhoneNumber)
{
formattedPhoneNumber = string.Empty;
if (string.IsNullOrWhiteSpace(phoheNumber)) return false;

formattedPhoneNumber = phoheNumber.Trim();
if (Regex.IsMatch(formattedPhoneNumber, @"^\+998\d{9}$"));
return false;
}
}
}

0 comments on commit 45663d7

Please sign in to comment.