1

I am trying to build an iOS app and I wish to validate whether a particular string that I have, is a valid email or not. The catch is, the string can be a non-english lanuage as well. Also, lets take Arabic for example, a language that is written Right to Left. So I wish to know how could I validate a non english string. (for the sake of simplicity, lets just assume that a valid email has the format "string+@+.+string").

Programming Language - Swift

I know that we can validate this using regEx

validEmail = "[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}" . . Now I am not sure how to do this if the language is not indian, and it is written Right to Left(like in Arabic, urdu, etc.)

  • Please also add the code where you use the regex. – Wiktor Stribiżew Nov 30 '22 at 12:51
  • Try `validEmail = "[\\w.%+-]+@(?:[\\p{L}\\p{M}\\d-]+\\.)+\\p{L}{2,4}"` or `validEmail = "^[\\w.%+-]+@(?:[\\p{L}\\p{M}\\d-]+\\.)+\\p{L}{2,4}\\z"` – Wiktor Stribiżew Nov 30 '22 at 12:52
  • See [this question](https://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-an-email-address) for some in-depth information on this topic. One question to ponder if it is really the responsibility off your app to make sure an email address is correct down to the finest detail, maybe it would be enough to only validate the pattern @? – Joakim Danielson Nov 30 '22 at 13:04
  • hmm Arabic's presentation is right to left, doesn't mean that string is reverse. So I think it's just a wrong regex maybe? – timbre timbre Nov 30 '22 at 15:20
  • Yea, I dont intend to do a fine check on an email. I do need to check only the pattern @JoakimDanielson, the only problem is I don't know how to pattern check non English characters. – ShadowMonarch Dec 01 '22 at 06:02

1 Answers1

0

Here's the validation to check if the string is in English language or not.

validEnglishAlphabets = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
  • I need to validate an email id that is already in Arabic(or any non English language). So I don't need to check if its english or not, I just need to be able to validate emails even if it is written in an Right To Left written languages. – ShadowMonarch Dec 01 '22 at 10:20