How can I force input to uppercase in an ASP.NET textbox?(如何在 ASP.NET 文本框中强制输入为大写?)
问题描述
我正在编写一个 ASP.NET 应用程序.我在网络表单上有一个文本框,我想强制用户输入的任何内容为大写.我想在前端做这个.您还应该注意,此文本框上有一个验证控件,因此我想确保该解决方案不会干扰 ASP.NET 验证.
I'm writing an ASP.NET application. I have a textbox on a webform, and I want to force whatever the user types to upper case. I'd like to do this on the front end. You should also note that there is a validation control on this textbox, so I want to make sure the solution doesn't interfere with the ASP.NET validation.
说明:似乎 CSS 文本转换使用户输入以大写形式显示.但是,在后台,由于验证控制失败,它仍然是小写字母.你看,我的验证控件检查是否输入了有效的状态代码,但是我使用的正则表达式只适用于大写字符.
Clarification: It appears that the CSS text transform makes the user input appear in uppercase. However, under the hood, it's still lower case as the validation control fails. You see, my validation control checks to see if a valid state code is entered, however the regular expression I'm using only works with uppercase characters.
推荐答案
为什么不使用 CSS 和后端的组合呢?使用:
Why not use a combination of the CSS and backend? Use:
style='text-transform:uppercase'
在文本框上,并在您的代码隐藏中使用:
on the TextBox, and in your codebehind use:
Textbox.Value.ToUpper();
您还可以轻松地将验证器上的正则表达式更改为使用小写和大写字母.这可能是比对它们强制大写更简单的解决方案.
You can also easily change your regex on the validator to use lowercase and uppercase letters. That's probably the easier solution than forcing uppercase on them.
这篇关于如何在 ASP.NET 文本框中强制输入为大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.NET 文本框中强制输入为大写?
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
