11import { describe , expect , test } from 'vitest' ;
2- import { postalCodeValidator as postalCodeValidatorNo } from './no' ;
3- import { postalCodeValidator as postalCodeValidatorSe } from './se' ;
2+ import {
3+ phoneNumberValidator as phoneNumberValidatorNo ,
4+ postalCodeValidator as postalCodeValidatorNo ,
5+ } from './no' ;
6+ import {
7+ phoneNumberValidator as phoneNumberValidatorSe ,
8+ postalCodeValidator as postalCodeValidatorSe ,
9+ } from './se' ;
410
511describe ( 'Norwegian' , ( ) => {
612 describe ( 'postalCodeValidator()' , ( ) => {
@@ -13,6 +19,23 @@ describe('Norwegian', () => {
1319 expect ( postalCodeValidatorNo ( 'not a number' ) ) . toBeFalsy ( ) ;
1420 } ) ;
1521 } ) ;
22+
23+ describe ( 'phoneNumberValidator()' , ( ) => {
24+ test ( 'validates phone numbers' , ( ) => {
25+ expect ( phoneNumberValidatorNo ( '22865500' ) ) . toBeTruthy ( ) ;
26+ expect ( phoneNumberValidatorNo ( '228655000' ) ) . toBeFalsy ( ) ;
27+
28+ expect (
29+ phoneNumberValidatorNo ( '40 00 00 00' , { mobileOnly : true } ) ,
30+ ) . toBeTruthy ( ) ;
31+ expect (
32+ phoneNumberValidatorNo ( '99 99 99 99' , { mobileOnly : true } ) ,
33+ ) . toBeTruthy ( ) ;
34+ expect (
35+ phoneNumberValidatorNo ( '22865500' , { mobileOnly : true } ) ,
36+ ) . toBeFalsy ( ) ;
37+ } ) ;
38+ } ) ;
1639} ) ;
1740
1841describe ( 'Swedish' , ( ) => {
@@ -27,4 +50,26 @@ describe('Swedish', () => {
2750 expect ( postalCodeValidatorSe ( 'not a number' ) ) . toBeFalsy ( ) ;
2851 } ) ;
2952 } ) ;
53+
54+ describe ( 'phoneNumberValidator()' , ( ) => {
55+ test ( 'validates phone numbers' , ( ) => {
56+ // should be 8 to 10 digits
57+ expect ( phoneNumberValidatorSe ( '08123456' ) ) . toBeTruthy ( ) ;
58+ expect ( phoneNumberValidatorSe ( '031123456' ) ) . toBeTruthy ( ) ;
59+ expect ( phoneNumberValidatorSe ( '0311234567' ) ) . toBeTruthy ( ) ;
60+
61+ // too short
62+ expect ( phoneNumberValidatorSe ( '0812345' ) ) . toBeFalsy ( ) ;
63+ // too long
64+ expect ( phoneNumberValidatorSe ( '0303123456789' ) ) . toBeFalsy ( ) ;
65+
66+ // cannot start with something other than 0
67+ expect ( phoneNumberValidatorSe ( '12345678' ) ) . toBeFalsy ( ) ;
68+
69+ // A Swedish mobile number is always 10 digits and starts with 07
70+ expect (
71+ phoneNumberValidatorSe ( '0712345678' , { mobileOnly : true } ) ,
72+ ) . toBeTruthy ( ) ;
73+ } ) ;
74+ } ) ;
3075} ) ;
0 commit comments