Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not getting how to validate the code please reply....
Posted
Comments
SoMad 28-Aug-13 0:53am    
What have you tried?

Soren Madsen

Please try following code

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="UserInterface.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function Validate()
        {
        var charactersOnly = document.getElementById('<%=txtName.ClientID %>').value;
        if (charactersOnly.search(/^[a-zA-Z]+$/) === -1)
        {
            alert("Only characters");
            document.getElementById('<%=txtName.ClientID %>').value = "";
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtName" runat="server"  onkeyup="Validate()" ></asp:TextBox>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
Member 14148652 14-Feb-19 7:00am    
where is WebForm2.aspx.cs page
Go through the below link.

http://www.w3resource.com/javascript/form/all-letters-field.php[^]

Hope this will help you.
 
Share this answer
 
<title>allow only alphabets(with space) in textbox using JavaScript


function onlyAlphabets(e, t) {
try {
if (window.event) {
var charCode = window.event.keyCode;
}
else if (e) {
var charCode = e.which;
}
else { return true; }
if ((charCode > 64 && charCode &lt; 91) || (charCode > 96 && charCode &lt; 123))
return true;
else
return false;
}
catch (err) {
alert(err.Description);
}
}









 
Share this answer
 
v2
Comments
Graeme_Grant 22-Aug-17 5:02am    
Why are you answering a 4-YEAR-OLD question? Please don't. There are plenty of current questions that require answering.

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