Commit 8e7720d3 authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FIX #16982 TIME 2:15 control phone format with regex

parent 7d3435fd
......@@ -12,7 +12,7 @@
</ion-item>
<ion-item>
<ion-label color="secondary" position="floating">{{'lang.phoneAlt' | translate}} *</ion-label>
<ion-input name="phone" pattern="^((\+)33)[1-9](\d{2}){4}$" (keyup)="formatPhone()" [(ngModel)]="otp.phone" placeholder="+33646342143" required></ion-input>
<ion-input name="phone" [pattern]="getRegexPhone()" [(ngModel)]="otp.phone" placeholder="+33646342143" required></ion-input>
</ion-item>
<ion-item>
<ion-label color="secondary" position="floating">{{'lang.email' | translate}} *
......
......@@ -63,7 +63,6 @@ export class OtpYousignComponent implements OnInit {
this.otp = {...this.otp, ...this.otpYousign};
this.otp.modes = this.roles;
this.otp.sourceId = this.connectorId;
this.formatPhone();
}
resolve(true);
}),
......@@ -92,4 +91,24 @@ export class OtpYousignComponent implements OnInit {
this.otp.phone = this.otp.phone.replace('0', '+33');
}
}
getRegexPhone() {
// map country calling code with national number length
const phonesMap = {
'32': [8, 10], // Belgium
'33': 9, // France
'1' : 10, // United States
'27': 9 // South Africa
};
const regex = Object.keys(phonesMap).reduce((phoneFormats: any [], countryCode: any) => {
const numberLength = phonesMap[countryCode];
if (Array.isArray(numberLength)) {
phoneFormats.push('(\\+' + countryCode + `[0-9]\{${numberLength[0]},${numberLength[1]}\})`);
} else {
phoneFormats.push('(\\+' + countryCode + `[0-9]\{${numberLength}\})`);
}
return phoneFormats;
}, []).join('|');
return new RegExp(`^(${regex})$`);
};
}
  • Le contrôle est fait pour les formats des téléphones des Pays: France, Belgique, États Unis et Afrique du Sud.

Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment