App.component.html
<form [formGroup]="exampleForm">
<div class="form-group">
<label>First Name</label>
<input type="text" formControlName="phoneNumber" class="form-control" >
</div>
</form>
App.component.ts
exampleForm: FormGroup;
number_pattern=' ^[0-9_-]*$ ';
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.exampleForm = this.formBuilder.group({
phoneNumber: ['', Validators.required, Validators.pattern(number_pattern)]
});
}
I need regex for phone with following rules, I tried regex code but its not working.
- Field must not be empty.
- Hyphens and space will accept in between the number not the starting and ending.
- Must not contain anything other than numbers or blank spaces or hyphens
- Field must not contain only blank space
- Field must not contain only hyphens
- Field must not contain only hyphens and blank space.
Thanks in advance.