@@ -16,12 +16,12 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
1616
1717 // 2. Define allowed strict formats
1818 // - with spaces: "CHXX XXXX XXXX XXXX XXXX X"
19- const compactIbanNumberWithWhiteSpaces = new RegExp ( / ^ C H \d { 2 } (?: \d { 4 } ) { 4 } \d { 1 } $ / ) ;
19+ const compactIbanNumberWithWhiteSpaces = new RegExp ( / ^ C H [ 0 - 9 ] { 2 } [ 0 - 9 ] { 4 } [ 0 - 9 ] [ A - Z 0 - 9 ] { 3 } [ A - Z 0 - 9 ] { 4 } [ A - Z 0 - 9 ] { 4 } [ A - Z 0 - 9 ] $ / ) ;
2020 // - without spaces: "CHXXXXXXXXXXXXXXXXXXX"
21- const compactIbanNumberWithoutWhiteSpaces = new RegExp ( / ^ C H \d { 19 } $ / ) ;
21+ const compactIbanNumberWithoutWhiteSpaces = new RegExp ( / ^ C H [ 0 - 9 ] { 7 } [ A - Z 0 - 9 ] { 12 } $ / ) ;
2222
23- // 3. Check if input matches one of the allowed formats
24- if ( ! compactIbanNumberWithWhiteSpaces . test ( ibanNumber ) && ! compactIbanNumberWithoutWhiteSpaces . test ( ibanNumber ) ) {
23+ // 3. Check if the input matches one of the allowed formats
24+ if ( ! ( compactIbanNumberWithWhiteSpaces . test ( ibanNumber ) || compactIbanNumberWithoutWhiteSpaces . test ( ibanNumber ) ) ) {
2525 return false ;
2626 }
2727
@@ -46,7 +46,7 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
4646}
4747
4848/**
49- * Validation of social insurance number with checking the checksum
49+ * Validation of a social insurance number with checking the checksum
5050 * Validation according to https://www.sozialversicherungsnummer.ch/aufbau-neu.htm
5151 * @param socialInsuranceNumber The social insurance number to check
5252 * Must be in one of the following formats:
@@ -55,13 +55,13 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
5555 * @returns The result if the social insurance number is valid or not
5656 */
5757export function isValidSwissSocialInsuranceNumber ( socialInsuranceNumber : string ) : boolean {
58- // 1. Check if input is empty or only whitespace
58+ // 1. Check if the input is empty or only a whitespace
5959 if ( isNullOrWhitespace ( socialInsuranceNumber ) ) {
6060 return false ;
6161 }
6262
6363 /**
64- * 2. Check if input matches accepted formats:
64+ * 2. Check if the input matches one of the accepted formats:
6565 * - With dots: 756.XXXX.XXXX.XX
6666 * - Without dots: 756XXXXXXXXXX
6767 */
0 commit comments