Skip to content
Snippets Groups Projects
Commit 94ff03a7 authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

fix(dev) : update regex phone + add space every 2 numbers

parent e1217faf
Branches
Tags
2 merge requests!68Recette,!67Dev
......@@ -55,7 +55,7 @@
</div>
<p>VOUS JOINDRE</p>
<p>Téléphone*</p>
<input type="text" formControlName="contactPhone" />
<input type="text" formControlName="contactPhone" (input)="modifyPhoneInput($event.target.value)" />
<app-validator-form [control]="getStructureControl('contactPhone')"></app-validator-form>
<p>Courriel*</p>
<input type="email" formControlName="contactMail" />
......
......@@ -87,7 +87,10 @@ export class FormComponent implements OnInit {
street: new FormControl(structure.address.street, Validators.required),
commune: new FormControl(structure.address.commune, Validators.required),
}),
contactPhone: new FormControl(structure.contactPhone, [Validators.required, Validators.pattern('[0-9]{10}')]),
contactPhone: new FormControl(structure.contactPhone, [
Validators.required,
Validators.pattern('([0-9]{2} ){4}[0-9]{2}'),
]),
contactMail: new FormControl(structure.contactMail, [
Validators.required,
Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,3}$'),
......@@ -149,6 +152,16 @@ export class FormComponent implements OnInit {
return this.structureForm.get('address').get(nameControl);
}
public modifyPhoneInput(phoneNumber: string): void {
// Take length of phone number without spaces.
let phoneNoSpace = phoneNumber.replace(/\s/g, '');
// Check to refresh every 2 number.
if (phoneNoSpace.length % 2 == 0) {
// Add space every 2 number
this.structureForm.get('contactPhone').setValue(phoneNoSpace.replace(/(?!^)(?=(?:\d{2})+$)/g, ' '));
}
}
public getTime(day: string): FormArray {
return this.structureForm.get('hours').get(day).get('time') as FormArray;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment