【发布时间】:2020-04-18 23:29:26
【问题描述】:
我可以使用文本框根据所选语言输入不同的语言吗,例如
如果我选择印地语,我将能够在文本框中输入印地语 如果我选择英语,我将能够输入英语
我们可以在 aspx、c# web 应用程序中做到这一点
【问题讨论】:
标签: javascript c# html asp.net
我可以使用文本框根据所选语言输入不同的语言吗,例如
如果我选择印地语,我将能够在文本框中输入印地语 如果我选择英语,我将能够输入英语
我们可以在 aspx、c# web 应用程序中做到这一点
【问题讨论】:
标签: javascript c# html asp.net
您可以触发“文本更改”事件并验证您的文本。 将最后一个文本保留为全局/静态变量,并检查新值。如果合法,则将变量替换为新文本。否则,强制文本框文本成为最后一个有效文本。 结果是用户将无法键入非法字符(或粘贴非法文本)。 您还可以引发错误、为文本框着色等...
如果用户试图添加一个字符 比如:
<iframe>
<asp:ComboBox ID="ComboBox1" runat="server" AutoPostBack="true"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
</iframe>
private string _currentValue
private const string allowedEnglish = "abcdefg........?.:123456789.....";
private const string allowedSpanish = "abcdefg...?.:123456789....áéíóúüñ¿¡......";
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
bool isValid = false;
switch(ComboBox1.SelectedValue)
{
case "English":
isValid = Regex.IsMatch(allowedEnglish, TextBox1.Value);
break;
case "Spanish":
isValid = Regex.IsMatch(allowedSpanish, TextBox1.Value);
break;
}
if(isValid)
_currentValue = TextBox1.Value;
else
TextBox1.Value = _currentValue;
}
当然,您可以将其扩展到更多语言,使用其他语言验证技术并改变客户体验,但这就是想法...
【讨论】: