在我的文本框中限制撇号 [英] Restrict apostrophes in my text box

查看:68
本文介绍了在我的文本框中限制撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制用户使用ajaxControl在我的文本框中仅输入撇号



我尝试过:



i试过这段代码

document.getElementById('yourTextBoxID')。onkeypress = function(){

if(event。 keyCode === 39)

返回false;

}

};

但我不想要在java脚本中。

i想要使用Ajax控件。

How do i restrict user to enter only apostrophes in my text box using ajaxControl

What I have tried:

i tried this code
document.getElementById('yourTextBoxID').onkeypress = function () {
if (event.keyCode === 39)
return false;
}
};​
but i do not want in java script.
i want to use Ajax control.

推荐答案

你不想在那里进行按键的字符验证服务器 - 它的效率非常低,在带宽,资源和服务器处理方面极其浪费,并为用户带来了可变但令人讨厌的延迟程度。



你这样做在客户端本地处理,而不是在服务器上 - 这意味着javascript,因为它是客户端上运行的唯一语言。所有VB代码都在服务器上运行。





You do not want to do key-by-key character validation at the server - it's monumentally inefficient, incredibly wasteful in bandwidth, resources, and server processing, and introduces a variable-but-nasty degree of lag to the user.

You do that kind of processing locally on the client, not on the server - and that means javascript because it's the only language that runs on the client. All VB code runs on the server.


Quote:

但这也不起作用。

But this isn't working either.

document.getElementById('yourTextBoxID').onkeypress = function () {
if (event.keyCode === 39)
return false;
}
};​



请有人帮忙,因为这个问题我的整个应用程序都被卡住了。


Please someone help, my entire app is stuck because of this issue.





试试这个:



Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>  
  <head>  
    <meta http-equiv="content-type" content="text/html; charset=windows-1250">  
    <title></title> 
    <script type="text/javascript">
      function blockSpecialChar(e) {
          var k = e.keyCode;
          return (k != 39);
      }
    </script>
  </head>  
  <body>
     <form id="frm" runat="server">
       <input type="text" name="name"  onkeypress="return blockSpecialChar(event)"/>
     </form>
  </body>
</html>


我使用它来获得仅数字输入(javaScript ):



I use this to have a numbers-only input (javaScript):

function intOnly(teststring) {
var len = testString.length;
  if(len > 0)
    testString = testString.replace(/\D/g , "");

return teststring;
} // function intOnly(teststring)





我使用函数return来更新控件的值。 />
根据您正在做的事情,您可以使用一个或多个事件来触发测试,例如onkeyup()或onblur()。 &NBSP;如果你使用onchange(),它通常需要两次访问函数 - 甚至陷入永久循环。



现在 - 去一个正则表达式(常规)表达式)教程 [ ^ ]并了解如何处理任何字符的任何文字。




I use the function return to update the value of the control.
Depending upon what you're doing, you can use one or more events to trigger the test, such as onkeyup() or onblur().   If you use onchange(), it will often take two trips to the function - or even get stuck in a perpetual loop.

Now - go to a regex (regular expressions) tutorial[^] and learn how you can process any text for any characters.


这篇关于在我的文本框中限制撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆