File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Adia.Ssn.Tests/Validators
Adia.SsnValidator/Validators Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,12 @@ public void Setup()
25
25
[ TestCase ( "756.0298.4726.97" , true ) ]
26
26
[ TestCase ( "756.5113.6381.28" , true ) ]
27
27
[ 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 ) ]
29
31
[ TestCase ( "756.1234.5678.95" , false ) ]
30
32
[ TestCase ( "7561234567895" , false ) ]
31
33
[ TestCase ( "75612345648955" , false ) ]
32
-
33
34
public void ValidateAhvNumberAsExpected ( string ssn , bool expectedResult )
34
35
{
35
36
var result = _validator . Validate ( ssn ) ;
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Text . RegularExpressions ;
3
4
4
5
namespace Adia . SsnValidator . Validators
5
6
{
6
7
public class AhvValidator : IValidator
7
8
{
8
9
public bool Validate ( string ahv )
9
10
{
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 ) )
12
13
{
13
14
return false ;
14
15
}
15
16
17
+ var ahv13 = ahv . Where ( char . IsDigit ) . ToArray ( ) ;
16
18
var ahv12 = ahv13 . Take ( 12 ) . Reverse ( ) . ToArray ( ) ;
17
19
var totalChecksum = 0 ;
18
20
for ( var i = 0 ; i < 12 ; i ++ )
You can’t perform that action at this time.
0 commit comments