文本框字符长度检查
问题描述:
对于c#中的文本框,如何在检查计数之前让文本框等待完成后输入所有字符?如果我有条件检查变量长度是否小于6并发出消息(如果是),我想等到我在检查之前输入所有字符,而不是在每个字符后发出消息。
我尝试过:
For textbox in c#, how to I get textbox to wait unti im finished typing all the characters before checking the count? If I have a condition to check if a variable length is less than 6 and issue a message if it is, i want to wait until i input all the characters before checking, rather than issuing the message after every character.
What I have tried:
Textbox character length check
答
等到提交检查所有字段并仅显示1或2条顶部消息,而不是尝试控制焦点。
您可以在OnLostFocus等消息区域中发布错误(这样用户可以返回),但更需要编程 (键盘,鼠标,触摸,激活/停用等)。
It's simpler to wait until "submit" to check "all" fields and show only 1 or 2 top messages, instead of trying to control "focus".
You can post errors in a message area from OnLostFocus and the like (so user can "go back"), but anything more requires "programming" (keyboard, mouse, "touch", activate / deactivate, etc.).
你应该使用客户端验证。
您可以查看onblur事件,了解插入文本框的字符长度。
HTML
You should use client side validation for same.
You can check onblur event for the length of a characters inserted into the textbox.
HTML
<input type="text" onblur="return myFunction()">
脚本
Script
function myFunction(){
var iCount =
( #txtValue ).VAL();
if (iCount> 6 ){
返回 true ;
} else {
alert( 您的提示信息);
return false ;
}
}
("#txtValue").val(); if(iCount > 6){ return true; }else{ alert("Your alert message"); return false; } }
或
你也可以设置按钮点击事件的验证,而不是模糊或textchanged事件。
如果你使用服务器端文本框(asp :)然后设置 AutoPostBack = False