0

I have developed a registration form to allow users to signup for a new account.

in the registration form in Ionic2 and I have to validate some values in the form before submit, one of the values (Full Name) may include either English or Arabic Characters

I used form validation concept as following:

this.personalInfoForm = formBuilder.group({
  txtFullName: ['', Validators.compose([Validators.minLength(6), Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required])],
  txtNickname: ['', Validators.compose([Validators.minLength(6), Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*'), Validators.required])],
  SGender: ['', Validators.required],
  txtCommercialName: ['', Validators.compose([Validators.minLength(6), Validators.maxLength(30), Validators.pattern('[a-zA-Z ]*')])],
  txtDateOfBirth: ['', Validators.required],
});

my problem is that the validator only accept English characters and when user enter Arabic characters the validator doesn't recognize it as a valid value so it doesn't accept it

Are there any pattern to make the validator accept Arabic characters, English characters, space

Yazan Allahham
  • 174
  • 2
  • 17
  • check https://stackoverflow.com/a/150078/4826457 – Suraj Rao Aug 18 '17 at 11:41
  • @suraj thank you very much...Can you post it as an answer so I can accept it...I found that i have to include \u0600-\u06FF in the pattern...that is what it is written in the link you provided – Yazan Allahham Aug 18 '17 at 12:02

1 Answers1

2

You are currently validating only english characters: Validators.pattern('[a-zA-Z ]*').

You need to find the unicode characters required for the non english language you are validating for.Check Jeremy Ruten's answer. The arabic character set as mentioned here will be \u0600-\u06FF.

So your pattern for English and Arabic would be

Validators.pattern('[a-zA-Z\u0600-\u06FF ]*')

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103