除此字符外的正则表达式 [英] Regular Expression Except this Characters

查看:39
本文介绍了除此字符外的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MVC 数据注释,我的要求是地址字段可以包含除 < 之外的任何字符(即也允许使用英文字符以外的字符).>.!@#%/?*.

I am using MVC data annotations and my requirement is that the address field can contain any characters (i.e. other than English characters are also allowed) except < > . ! @ # % / ? *.

我搜索了很多网站,但不知道如何编写这个正则表达式.

I searched many sites but not getting how to write this regex.

到目前为止我已经尝试过:

So far I have tried:

[Required(ErrorMessage = "Address Required.")]
[RegularExpression(@"^[<>.!@#%/]+$", ErrorMessage = "Address invalid.")]
public string Address { get; set; }

推荐答案

目前,您只允许只包含这些字母的字符串.

Currently, you are only allowing string consisting ONLY of these letters.

使用

"^[^<>.!@#%/]+$"

这篇关于除此字符外的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆