开发者

How to avoid input space and special character

I work on asp.net C# Window application. in AspxText开发者_开发技巧box I want to avoid space and arrow key and also special character. I want just user can input number 0 to 9 and a to z character.


I would suggest that you use the following code:

      <dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px">
        <ClientSideEvents KeyPress="function(s, e) { 
if( 
      (e.htmlEvent.keyCode &gt;= 48 &amp;&amp; e.htmlEvent.keyCode &lt;= 57) ||
      (e.htmlEvent.keyCode &gt;= 97 &amp;&amp; e.htmlEvent.keyCode &lt;= 122) ) 

  {  }
  else { _aspxPreventEvent(e.htmlEvent); }
}"/>
        </dx:ASPxTextBox>


It appears the DevExpress AspxTextbox allows you to specify some JavaScript to achieve this. If you're inclined to use the DexExpress controls to their fullest, consider the ClientSideEvents element. The following JavaScript attached to the KeyPress event will allow numbers only.

  • 48 to 57 is to allow 0 through 9
  • 97 to 122 are a through z (lowercase)
  • if you require more ASCII values to be allowed, refer to the chart
<dxe:ASPxTextBox runat="server" EnableClientSideAPI="True" ID="foo"  
                 ClientInstanceName="bar">

  <ClientSideEvents KeyPress="function(s, e) {
  if( 
      (e.htmlEvent.keyCode >= 48 && e.htmlEvent.keyCode <= 57) ||
      (e.htmlEvent.keyCode >= 97 && e.htmlEvent.keyCode <= 122) ) 

  { return true; }
  else {  return false;}

  }" />                                         
</dxe:ASPxTextBox>

Of course, modify as you see fit, and as you require. More context at the DevExpress site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜