简体   繁体   English

如何限制用户在文本框中输入英文字符

[英]How to limit users from entering english characters in a textbox

Do I need to use regex to ensure that the user has typed in English? 我是否需要使用正则表达式来确保用户输入的是英文? All characters are valid except non English characters. 除非英文字符外,所有字符均有效。

How do I validate this textbox? 如何验证此文本框?

A regex would work quite well for this. 正则表达式对此非常有效。 Something like 就像是

^[a-zA-Z0-9 ?!.,;:$]*$ ^ [a-zA-Z0-9?!。,;:$] * $

would be a good starting point. 将是一个很好的起点。 It would allow all alphabetical and numerical characters, as well as some common punctuation. 它将允许所有字母和数字字符以及一些常见的标点符号。 You would need to change it depending on what your definition of English characters is. 您需要根据英文字符的定义进行更改。

See the regex docs here for more information. 有关更多信息,请参见regex文档

This has nothing to do with regular expressions and the link referred to by gurukulki does not answer the question either. 这与正则表达式无关,并且gurukulki引用的链接也无法回答问题。 To change language, you need to implement localization in your website: 要更改语言,您需要在网站中实现本地化:

http://www.west-wind.com/presentations/wwdbResourceProvider/introtolocalization.aspx link text http://www.west-wind.com/presentations/wwdbResourceProvider/introtolocalization.aspx 链接文本

http://www.codeproject.com/KB/aspnet/localizationByVivekTakur.aspx http://www.codeproject.com/KB/aspnet/localizationByVivekTakur.aspx

您可以使用FilteredTextBox表单ASP.NET AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM