如何在 ASP.NET 文本框中强制输入为大写?

10

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

The End

相关推荐

Func<string,string> 有什么区别?和委托?
What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)...
2023-11-11 C#/.NET开发问题
3

如何通过串口 RS-232 或 USB 转换器将体重秤的重量显示到文本框中?
How to display weight from weighing scale into a textbox via serial port RS-232 or usb converter?(如何通过串口 RS-232 或 USB 转换器将体重秤的重量显示到文本框中?)...
2023-11-10 C#/.NET开发问题
5

ASP.NET MVC 中的 <%: 和 <%= 有什么区别?
What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)...
2023-11-10 C#/.NET开发问题
0

标签系统的 linq 查询 - 搜索多个标签
linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)...
2023-11-10 C#/.NET开发问题
0

论坛标签.实施它们的最佳方法是什么?
Forum tags. What is the best way to implement them?(论坛标签.实施它们的最佳方法是什么?)...
2023-11-10 C#/.NET开发问题
1

正则表达式 - 我只想匹配正则表达式中的开始标签
Regex - I only want to match the start tags in regex(正则表达式 - 我只想匹配正则表达式中的开始标签)...
2023-11-10 C#/.NET开发问题
0