<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
标签 c# ios regex xamarin.forms
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
我正在使用以下正则表达式:
public const string SpecialCharRegex = @"^[A-Za-z0-9\s\(\)\.\&\-',`]+$";
我正在使用它来验证 iPhone 上我的 iOS 应用程序中的字段。
我喜欢匹配这个类中的所有字符。但是,我对打印智能/ curl 撇号有疑问。
例子:
My name is AB'c
没问题,但如果在 iPhone 上输入它会抛出错误。
事实证明,iOS 键盘并没有输入撇号‘(字符 39),而是一个 Unicode ‘智能’左引号(字符 8216)。如何调整模式以匹配弯引号?
最佳答案
有很多quotation mark那里的字符。
我想你也想捕获那些:
U+2018: LEFT SINGLE QUOTATION MARK
U+2019: RIGHT SINGLE QUOTATION MARK
U+201C: LEFT DOUBLE QUOTATION MARK
U+201D: RIGHT DOUBLE QUOTATION MARK
像这样添加它们,这样您的 character class : \uFFFF
或 \xFF
(参见 here)
string SpecialCharRegex = @"^[A-Za-z0-9\s\(\)\.\&\-',`\u2018\u2019\u201C\u201D]+$";
关于c# - 在 Regex C# 中允许撇号、点、符号、数字和字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647651/