-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HasNumbersOnly IsIntNumber IsLongNumber IsDecimalNumber Brazil functions included: IsMobileNumber (with area code validation)
- Loading branch information
Bruno de Souza Melo
committed
May 27, 2024
1 parent
8107e7c
commit 4fb1f95
Showing
7 changed files
with
159 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace NuvTools.Validation.Brazil; | ||
|
||
/// <summary> | ||
/// Regex patterns class. | ||
/// </summary> | ||
public static class RegexPattern | ||
{ | ||
/// <summary> | ||
/// Regex pattern for mobile phone validation. | ||
/// </summary> | ||
public const string MobileNumber = @"(?<CodeArea>11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|37|38|41|42|43|44|45|46|47|48|49|51|53|54|55|61|62|63|64|65|66|67|68|69|71|73|74|75|77|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)(?<FirstDigit>9)(?<Number>\d{8})"; | ||
} |
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
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
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,50 @@ | ||
using NUnit.Framework; | ||
using System.Globalization; | ||
|
||
namespace NuvTools.Validation.Tests; | ||
|
||
[TestFixture()] | ||
public class ValidatorExtensions | ||
{ | ||
[Test()] | ||
public void ValidateHasNumbersOnly() | ||
{ | ||
Assert.That("12345678910123456789101234567891012345678910123456789101234567891012345678910".HasNumbersOnly()); | ||
Assert.That("12345678910".HasNumbersOnly()); | ||
Assert.That(!"03.785.417".HasNumbersOnly()); | ||
Assert.That(!"-54243121000193".HasNumbersOnly()); | ||
} | ||
|
||
[Test()] | ||
public void ValidateIsIntNumber() | ||
{ | ||
Assert.That("111111111".IsIntNumber()); | ||
Assert.That(!"11111111111".IsIntNumber()); | ||
Assert.That("-111111111".IsIntNumber()); | ||
Assert.That(!"-111111111".IsIntNumber(true)); | ||
Assert.That(!"erro".IsLongNumber()); | ||
Assert.That(!"555.666.777-00".IsIntNumber()); | ||
} | ||
|
||
[Test()] | ||
public void ValidateIsLongNumber() | ||
{ | ||
Assert.That("11111111111".IsLongNumber()); | ||
Assert.That("-11111111111".IsLongNumber()); | ||
Assert.That(!"-11111111111".IsLongNumber(true)); | ||
Assert.That(!"erro".IsLongNumber()); | ||
Assert.That(!"555.666.777-00".IsLongNumber()); | ||
} | ||
|
||
[Test()] | ||
public void ValidateIsDecimalNumber() | ||
{ | ||
Assert.That($"583{CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator}08".IsDecimalNumber()); | ||
Assert.That("11111111111".IsDecimalNumber()); | ||
Assert.That("-11111111111".IsDecimalNumber()); | ||
Assert.That(!"-11111111111".IsDecimalNumber(true)); | ||
Assert.That(!"erro".IsDecimalNumber()); | ||
Assert.That("83289988074".IsDecimalNumber()); | ||
} | ||
|
||
} |