Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can i use the following code in javascript for validation:
The first one is for Name validation that name should not contain any numerals and second code is for phone number validation in which number should only starts with 97,98
function name()
       {
           var a;
           a = document.form1.TextBox1.value;
           for (i = 0; i < a.length; i++)
           {
               if (a.indexof(charCodeAt(i) > 48) != -1 && a.indexof(charCodeAt(i) < 58) != -1)
                {
                   alert("please enter valid name");
               }

           }
       }
       function phno()
       {
       var b;
       b = document.form1.TextBox4.value;
       if (b.charAt(0) == 57 && b.charAt(1) == 56)
       {
       alert("This number is acceptable");
       }
       else if (b.charAt(0) == 57 && b.charAt(1) == 55)
       alert("this number is acceptable");

   }
Posted
Updated 14-Jun-13 0:32am
v2
Comments
What is the Problem exactly? Why can't you use it? Have you tried?
Rambo_Raja 14-Jun-13 7:01am    
yes..
but its not working. i am creating a form in which i want the name field to be validate such that no one can enter numerals in name textbox similarly the phne no. fiels also should starts with 97,98 only.
Please check my answer and see the demo. I have modified a little to work this out for you.
Rambo_Raja 14-Jun-13 7:01am    
yes..
but its not working. i am creating a form in which i want the name field to be validate such that no one can enter numerals in name textbox similarly the phne no. fiels also should starts with 97,98 only.

1 solution

There are some problems in the code.

I have modified it to exclude the indexof function and changed the charAt to charCodeAt in phno().

And yes, function name can't be "name()", so I have changed to "nameValidation()".

Demo - [Demo] javaScript Validation for name and phone number issue[^].

Check how it is working.
 
Share this answer
 
Comments
Rambo_Raja 14-Jun-13 7:43am    
hmmm.i hope i could have check but my rest of code is not working...will definitely let u know.
Hi R_sharma,

Ok. You can add as many question as you want in Code Project, when you face any difficulty.

Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Tadit

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