RegEx模式只匹配某些字符 [英] RegEx Pattern to Match Only Certain Characters
本文介绍了RegEx模式只匹配某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是RegEx的新手,这个特殊问题令我感到沮丧。这适用于JavaScript函数。
I'm a newbie to RegEx, and this particular issue is flummoxing me. This is for use with a JavaScript function.
我需要验证输入,使其仅匹配此条件:
I need to validate an input so that it matches only this criteria:
- 字母AZ(大写和小写)
- 数字0-9
- 以下附加字符:space,句号(。),逗号(,),加号(+)和短划线( - )
我可以轻松写出一个模式对于前两个标准,但第三个标准更难。这是我管理的最后一个模式,但它似乎不适用于测试字符串 Farh %% $$ +++,
I can write a pattern easily enough for the first two criteria, but the third one is more difficult. This is the last pattern I managed, but it doesn't seem to work with the test string Farh%%$$+++,
非常感谢任何帮助。
谢谢。
推荐答案
我刚刚对此进行了测试,它似乎至少在我的第一轮测试中起作用。
I just tested this out, and it seems to work at least from my first round testing.
^[a-zA-Z 0-9\.\,\+\-]*$
这篇关于RegEx模式只匹配某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文