Skip to content

Commit 60508ce

Browse files
authored
Merge pull request #1 from adia-technology/Add_AHV_format_validation
Add AHV format validation
2 parents df3a678 + 65ed8e1 commit 60508ce

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Adia.Ssn.Tests/Validators/AhvValidatorTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ public void Setup()
2525
[TestCase("756.0298.4726.97", true)]
2626
[TestCase("756.5113.6381.28", true)]
2727
[TestCase("756.5466.9658.89", true)]
28-
[TestCase("7561656967213", true)]
28+
[TestCase("756.5466.965889", false)]
29+
[TestCase("755:5466.9658.89", false)]
30+
[TestCase("7561656967213", false)]
2931
[TestCase("756.1234.5678.95", false)]
3032
[TestCase("7561234567895", false)]
3133
[TestCase("75612345648955", false)]
32-
3334
public void ValidateAhvNumberAsExpected(string ssn, bool expectedResult)
3435
{
3536
var result = _validator.Validate(ssn);

Adia.SsnValidator/Validators/AhvValidator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
using System;
22
using System.Linq;
3+
using System.Text.RegularExpressions;
34

45
namespace Adia.SsnValidator.Validators
56
{
67
public class AhvValidator : IValidator
78
{
89
public bool Validate(string ahv)
910
{
10-
var ahv13 = ahv.Where(char.IsDigit).ToArray();
11-
if(ahv13.Count() != 13)
11+
var regex = new Regex(@"^756\.\d{4}\.\d{4}\.\d{2}$");
12+
if(!regex.IsMatch(ahv))
1213
{
1314
return false;
1415
}
1516

17+
var ahv13 = ahv.Where(char.IsDigit).ToArray();
1618
var ahv12 = ahv13.Take(12).Reverse().ToArray();
1719
var totalChecksum = 0;
1820
for (var i = 0; i < 12; i++)

0 commit comments

Comments
 (0)