USACanadaSSN (SSN;USACanada)

This function validates Canadian Social Security Numbers ( using the Luhn function ) and correctly formats both US and Canadian SSN numbers.

USACanadaSSN (SSN;USACanada)

/*

This function validates Canadian Social Security Numbers ( using the Luhn function ) and

correctly formats both US and Canadian numbers.

*/

// remove any non-number

Let( [ JustNum= Filter( SSN ; "0123456789" ) ;

validCanSS = If ( USACanada = "Canada" ; Luhn ( SSN ) ; "" ) ; // Validate Canadian numbers using the Luhn algorithm.

invalidCanSS = If ( validCanSS = 1 ; "" ; "Invalid Number " ) ;

formatted =

Case (

USACanada = "USA" ; Left( JustNum ; 3 ) & "-" & Middle( JustNum ; 4 ; 2 ) & "-" & Middle( JustNum ; 6 ; 4 ) ;

USACanada = "Canada" ; Left( JustNum ; 3 ) &"-" & Middle( JustNum ; 4 ; 3 ) &"-" & Middle( JustNum ; 7 ; 3 )

) // close case

] ; // close let variable definition

//Set clolor to red if invalid number of digits.

Case (

USACanada = "" ; SSN ; // returns the unmodified string if USACanada is blank

SSN = "" ; SSN ; // returns blank if SSN is blank

Length ( JustNum ) ≠ 9 or validCanSS = 0 ; TextColor ( invalidCanSS & formatted ; RGB ( 255 ; 0 ; 0 ) ) ;

TextColor ( formatted ; RGB ( 0 ; 0 ; 0 ) )

) // close case

) // close let




Contact Us | Privacy | Policies

Copyright © 2006 DataIsland Software LLC. All rights reserved.

Notice: Product specifications and availability are subject to change without notice.