Click here to Skip to main content
15,917,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i just need to validate 3 textboxes in asp.net using javascript.i need to check whether textbox is null or textbox is having any integer values.if so it must give an alert saying only alphabets are allowed...this should be done when one save button is clicked.for doing i jst added one javascript file....i dont know the coding part,,,can anyonw plss help me............
Posted

 
Share this answer
 
Comments
amaljosep 17-Feb-12 4:46am    
i am using a content page of my master page....wheather it makes any difference?if no then where to put the script tag in content page.
Hi, for validate only you can enter alpha numeric then

add attribute on textbox
C#
txtBox.attributes.add("onkeypress", "javascript:return isAlphaNumeric(event);");


JS function
JavaScript
function isAlphaNumeric(e)
 {
//    alert(e.which);
    if ((e.which < 48 || e.which > 57))
    {
        if ((e.which < 123 && e.which > 96))
        {
            return true;
        }
        if ((e.which < 91 && e.which > 64))
        {
            return true;
        }
        if (e.which == 8 || e.which == 0 || e.which == 32)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
 
Share this answer
 
Comments
amaljosep 17-Feb-12 4:47am    
i am using a content page of my master page....wheather it makes any difference?if no then where to put the script tag in content page.
[no name] 18-Feb-12 7:14am    
you can use separate js file or you can write js function on page html at above of asp:content tag.
below of page directive.

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