Advertisement
viditkothari

Assignment8

Sep 15th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.66 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Assignment #8</title>
  5.     </head>
  6.     <body>
  7.         <script type="text/javascript">
  8.         function checkName(){
  9.                 var var_name=document.getElementById('nm').value;
  10.                 var stl=var_name.length;
  11.                 var i;
  12.                 for(i=0;i<stl;i++) {
  13.                        if(!(isNaN(var_name.charAt(i)))) {
  14.                            console.log('The name cannot contain a numeric value : '+var_name.charAt(i));
  15.                            return 0;
  16.                        }
  17.                }
  18.                console.log('Valid Name');
  19.            }
  20.            function checkAge(){
  21.                var var_age=document.getElementById('ag').value;
  22.                if(var_age>=18)
  23.                     console.log("Ok");
  24.                 else
  25.                     console.log("Invalid Age!");
  26.             }
  27.             function checkEmail(){
  28.                 var var_mail=document.getElementById('eml').value;
  29.                 var stl=var_mail.length;
  30.                 var charr=new Array(6);
  31.                 charr[0]='#';
  32.                 charr[1]='%';
  33.                 charr[2]='+';
  34.                 charr[3]='-';
  35.                 charr[4]=')';
  36.                 charr[5]='^';
  37.                 var count1=0,count2=0;
  38.                 for(var i=0;i<stl;i++) {
  39.                    if(var_mail.charAt(i)=='@' || var_mail.charAt(i)=='.')
  40.                        count1++;
  41.                        for(j=0;j<6;j++) {
  42.                            if(var_mail.charAt(i)==charr[j])
  43.                                count2++;
  44.                    }
  45.                }
  46.                if(count1<3 && count2>0)
  47.                 console.log("Invalid Email!");
  48.             }
  49.             function checkPass(){
  50.                 var var_pass=document.getElementById('pass').value;
  51.                 var var_cpass=document.getElementById('cpass').value;
  52.                 if(var_pass==var_cpass)
  53.                     console.log("Password matched");
  54.                 else
  55.                     console.log("Password match required");
  56.             }
  57.             function vldt() {
  58.                 checkName();
  59.                 checkAge();
  60.                 checkEmail();
  61.                 checkPass();
  62.             }
  63.     </script>
  64.     <form>
  65.         Name : <input type="text" name="nm" id="nm"><br/>
  66.     Age : <input type="text" name="ag" id="ag"><br/>
  67.     Email ID : <input type="text" name="eml" id="eml"><br/>
  68.     Password : <input type="text" name="pass" id="pass"><br/>
  69.     Confirm Password : <input type="text" name="cpass" id="cpass"><br/>
  70.     <input type="button" value="Validate" onclick="vldt()">
  71.     </form>
  72.     </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement