Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I'm in need of help to get the coding for Username validation.When i'm entering characters it should accept other than characters if im entering numbers it should not accept and it should show the message "Invalid Character"

Regards
Balamurugan
Posted

Try this

C#
function fnvalidate() {
        if (!form1.TextBox1.value.match(/^[a-zA-Z]+$/) && form1.TextBox1.value != "") {
            form1.TextBox1.value = "";
            form1.TextBox1.focus();
            alert("only alphabets are allowed as UserName");
        }
    }


Call the function in onblur event of ur control on client side
 
Share this answer
 
function isNumberKey(evt) {
           var charCode = (evt.which) ? evt.which : event.keyCode
           if ((charCode < 48 || charCode > 57))
               return false;
           return true;
       }
Client Side Coding Call OnKeyPress Event
 
Share this answer
 
Comments
[no name] 9-Oct-12 0:14am    
I forget the coding which i know in that we mentioned parse values...Your coding is not accepting it.
function isNumberKey(evt) {
           var charCode = (evt.which) ? evt.which : event.keyCode
           if ((charCode < 48 || charCode > 57))
               return false;
           return true;
       } Client Side Coding Call OnKeyPress Event
 
Share this answer
 
Comments
[no name] 9-Oct-12 0:16am    
it is not working

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