Javascript RegExp dosn't recognize apostrophe on mobile iOS

后端 未结 2 1662
青春惊慌失措
青春惊慌失措 2021-01-24 02:39

I have a form with three input.
The first is only number and for the other two I can accept all letters from A to Z, space and apostrophe.

HTML

相关标签:
2条回答
  • 2021-01-24 03:10

    Thanks to @Wiktor Stribiżew for the help.
    The correct string is new RegExp("^[a-zA-ZÀ-ÿ ‘’']{2,60}$")
    I also have find this link that can help.

    0 讨论(0)
  • 2021-01-24 03:14

    If the "Smart Punctuations" are switched on all straight single apostrophes are automatically converted to curly apostrophes. Even if you have access to the smartQuotesType property of UI text input fields, users may paste curly apostrophes there and you should account for them.

    In the Regex and Smart Punctuation in iOS post, the author suggests adding ‘’ to the regex:

    let regexMessaggio2 = /^[a-zA-ZÀ-ÿ ‘’']{2,60}$/;
    

    Or, in case there are any encoding issues use hex representations:

    let regexMessaggio2 = /^[a-zA-ZÀ-ÿ \u2018\u2019']{2,60}$/;
    

    Note that a regex literal notation (/.../) is preferable to the RegExp constructor notation when the pattern is static, i.e. you are not passing any variables to the regex pattern.

    0 讨论(0)
提交回复
热议问题