正则表达式,不允许用户输入NA或N/A或na或n/a [英] Regular expression to not allow users to enter NA or N/A or na or n/a

查看:65
本文介绍了正则表达式,不允许用户输入NA或N/A或na或n/a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,用户正在输入na而不是提供指定的数据.如何明确不允许他们在字段中输入na?我想使用一个aspregularexpressionvalidator.

I have a text box and users are entering na rather than supplying the specified data. How can explicitly not allow them to enter na in the field? I want to use an asp regularexpressionvalidator.

推荐答案

^(?!\s*n\s*/?\s*a\s*$).*

如果用户输入除 n/a 以外的任何内容,

将匹配(并返回输入字符串),否则失败.如果选择不区分大小写的匹配,则涵盖了问题中的所有变体(在.NET中,这是使用选项 RegexOptions.IgnoreCase 完成的).另外,任何数量的空格都将被忽略,因此用户不能简单地键入 n/a .

will match (and return the input string) if the user enters anything except n/a and fail otherwise. All the variations in your questions are covered if you select case-insensitive matching (in .NET, this is done using the option RegexOptions.IgnoreCase). Also, any amount of whitespace will be ignored so the user can't simply type n / a.

这篇关于正则表达式,不允许用户输入NA或N/A或na或n/a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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