I am developing ionic app in which i want to allow everything alphabets, number and special characters also.
Here is my code i have wrote but it is not allowing me to enter hyphen and some special characters.
home.html
<form [formGroup]="myForm2">
<ion-item>
<ion-label class="labelColor" stacked>
Ship register Number
<ion-icon name="ios-medical" class="iconStar"></ion-icon>
</ion-label>
<ion-input formControlName="ship_reg_no" type="text" [class.invalid]="!myForm1.controls.ship_reg_no.valid && (myForm1.controls.ship_reg_no.dirty || submitAttempt)" maxlength="50" >
</ion-input>
</ion-item>
</form>
home.ts
ngOnInit(){
this.myForm1 = this._fb.group({
ship_reg_no: ["", Validators.compose([Validators.pattern(GlobalValidators.Allow_All_Regex), Validators.required])]
});
validaotr.ts
export class GlobalValidators {
public static EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
public static Allow_All_Regex = '[A-Za-z0-9_@./#&-+,!\-$(); ]*';
}
Please help and thank you in advance!