【问题标题】:Validation Check for non-english stringsValidation Check for non-english strings
【发布时间】:2022-12-01 13:39:16
【问题描述】:

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.
  • 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"
  • See this question 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 <local part>@<domain>?
  • 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?

标签: ios swift regex validation


【解决方案1】:

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

validEnglishAlphabets = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-28
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多