需要.net正则表达式来阻止所有空格和@字符(Need a .net regex to block all spaces and the @ character)

我有.net表达式来阻止空格,但不知道如何修改它以阻止@字符。

当前表达式来阻止空格: ^\s*\S+\s*$

I have the .net expression to block spaces but no idea how to modify it to also block the @ character.

Current expression to block spaces: ^\s*\S+\s*$

最满意答案

通过使用^ inside [ ]来阻止你不想匹配的内容:

^[^\s@]+$

演示

By using ^ inside [ ] to block what you don't want to be matched :

^[^\s@]+$

demo

需要.net正则表达式来阻止所有空格和@字符(Need a .net regex to block all spaces and the @ character)

我有.net表达式来阻止空格,但不知道如何修改它以阻止@字符。

当前表达式来阻止空格: ^\s*\S+\s*$

I have the .net expression to block spaces but no idea how to modify it to also block the @ character.

Current expression to block spaces: ^\s*\S+\s*$

最满意答案

通过使用^ inside [ ]来阻止你不想匹配的内容:

^[^\s@]+$

演示

By using ^ inside [ ] to block what you don't want to be matched :

^[^\s@]+$

demo