我正在编写一个 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 文本框中强制输入为大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!