-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1543272
commit 45663d7
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |