Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a login form. I want to not allow space when entreing password in textbox.
Or
when entreing space at that time a alert message show.
Posted

XML
<input type="text" id="txtSearch" onkeypress="KeyPress(event);" />

<script>
    function KeyPress(e)
    {
       
        if (typeof e == 'undefined' && window.event) { e = window.event; }
        if (e.keyCode == 32)
        {
            alert('Space not allowed');
        }
    }
    </script>
 
Share this answer
 
Hi,
Try this:
HTML:
ASP.NET
<asp:TextBox runat="server" ID="TextBox1" onkeypress="KeyPress(this);" />

JavaScript:
JavaScript
<script type="text/javascript" language="javascript">
    function KeyPress(value)
    {
        if (value.keyCode == 32)
        {
            alert('Space not allowed');
            return false;
        }
    }
</script>


All the best.
--Amit
 
Share this answer
 
v4
C#
if (value.keyCode == 32)
        {
            alert('Dont Type Space');
            return false;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900