2

I would like to have a regular expression that matches:

1.Arabic letters.

2.English letters.

3.Allow space.

4.min 2-max 30.

then i wrotre this regex:

^(?:[a-zA-Z\s\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]|(?:\uD802[\uDE60-\uDE9F]|\uD83B[\uDE00-\uDEFF])[ ]{0,1}){2,30}$

but its not good

dee-see
  • 23,668
  • 5
  • 58
  • 91
sara
  • 55
  • 1
  • 7
  • If it doesn’t need to be specifically Arabic and English letters, but could be letters of any language you could just use `\P{L}` which would match any Unicode letter. – ckuri Mar 23 '21 at 23:58

1 Answers1

2

If an Arabic letter regex is [\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF] (see Regular Expression not to allow numbers - just Arabic letters) and English letters are [a-zA-Z], you can use

^(?=.{2,30}$)[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z]+(?:\s[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z]+)?$

Details:

  • ^ - start of string
  • (?=.{2,30}$) - the string must be 2 to 30 chars long
  • [\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z]+ - one or more Arabic or English letters
  • (?:\s[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z]+)? - an optional occurrence of a whitespace and one or more Arabic or English letters
  • $ - end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563