Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my text box i need to enter only string instead of numbers, how can i validate in javascript
Posted
Updated 14-Dec-11 1:47am
v2

 
Share this answer
 
Hi,

Try to this java script code:

HTML
<script type="text/javascript">
                       
 function alpha(e) 
            { 
	    var k;
            document.all ? k = e.keyCode : k = e.which;
            return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k==32 || k==13);
	    }
</script>

ASP.NET
<asp:textbox id="txtpartyhallname" runat="server" width="200px" cssclass="WaterMarkedTextBox" onkeydown="return alpha(event)" xmlns:asp="#unknown"></asp:textbox>
 
Share this answer
 
v2
you just run the below code and learn

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Registration Form
</title>
<script type="text/javascript">
function check()
{
var ck_username = /^[A-Za-z]{3,20}$/;
d=document.form;
if (document.form.username.value.search(ck_username)==-1)
{
alert("Please only enter 6 to 12 alphabets");d.username.value='';d.username.focus();return false
}
else
{
alert("username validated OK.");d.username.value='';d.username.focus();return false}
}
</script>
</head>
<body>
<form style='margin-left:340px' name='form' action=" " method="POST" onsubmit="return check()">
<INPUT maxLength="12" type="text" name="username" size="12">
<INPUT TYPE="SUBMIT" value="Submit Username">
<INPUT TYPE="RESET" value="reset">
</form>
    </body>
</html>
 
Share this answer
 
 
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