限制扩展 ASCII 字符集的正则表达式 [英] Regular expression to restrict Extended ASCII character set
问题描述
我有创建 xml 文件的多语言应用程序,但不应该使用从 168 到 254 的扩展 ASCII 字符(¿⌐¬½¼¡«»░▓│┤╡╢╖╕╣║╗╜╛┐└┬├)在 XML 标签中,所以我想限制用户进入.
I have multi lingual application which creates xml files but Extended ASCII characters from 168 to 254 (¿⌐¬½¼¡«»░▓│┤╡╢╖╕╣║╗╜╛┐└┴┬├) are not supposed in XML tags so, I would like to restrict user from entering.
我尝试限制除字母数字、下划线和破折号之外的所有内容,但它不允许作为扩展 ASCII 一部分的重音字符 ó ç õ.这是regx "^[a-zA-Z0-9\s.\-_]+$"
I tried restricting everything besides alphanumeric, underscore and dash but it would not allow accented characters ó ç õ which are part of extended ASCII. Here is regx "^[a-zA-Z0-9\s.\-_]+$"
第二个选项是创建从 168 到 254 的所有符号的字符串,并检查字符串是否包含其中任何一个,但不确定它是否是可靠和准确的解决方案.
Second option was to create a string of all symbols from 168 to 254 and check if string contains any of them but not sure if it is reliable and accurate solution.
过滤扩展 ASCII 字符集输入的最佳方法是什么?
What is best way to filter input for Extended ASCII character set ?
链接到扩展 ASCII字符集表
Link to Extended ASCII character set table
推荐答案
虽然@Oded 建议适用,但我使用了以下解决方案:
Although @Oded suggest was applicable but I used following solution:
Dim filteredInput as string
Private const XML_RESTRICTED_CHARACTERS as string ="[☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼#$%&()*+,-./:;<=>?@[\]^_`¢£¥₧ƒªº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■""}{]"
filteredInput =Regex.Replace(strInput.ToLower(), XML_RESTRICTED_CHARACTERS, "")
这篇关于限制扩展 ASCII 字符集的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!