Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Assignment #8</title>
- </head>
- <body>
- <script type="text/javascript">
- function checkName(){
- var var_name=document.getElementById('nm').value;
- var stl=var_name.length;
- var i;
- for(i=0;i<stl;i++) {
- if(!(isNaN(var_name.charAt(i)))) {
- console.log('The name cannot contain a numeric value : '+var_name.charAt(i));
- return 0;
- }
- }
- console.log('Valid Name');
- }
- function checkAge(){
- var var_age=document.getElementById('ag').value;
- if(var_age>=18)
- console.log("Ok");
- else
- console.log("Invalid Age!");
- }
- function checkEmail(){
- var var_mail=document.getElementById('eml').value;
- var stl=var_mail.length;
- var charr=new Array(6);
- charr[0]='#';
- charr[1]='%';
- charr[2]='+';
- charr[3]='-';
- charr[4]=')';
- charr[5]='^';
- var count1=0,count2=0;
- for(var i=0;i<stl;i++) {
- if(var_mail.charAt(i)=='@' || var_mail.charAt(i)=='.')
- count1++;
- for(j=0;j<6;j++) {
- if(var_mail.charAt(i)==charr[j])
- count2++;
- }
- }
- if(count1<3 && count2>0)
- console.log("Invalid Email!");
- }
- function checkPass(){
- var var_pass=document.getElementById('pass').value;
- var var_cpass=document.getElementById('cpass').value;
- if(var_pass==var_cpass)
- console.log("Password matched");
- else
- console.log("Password match required");
- }
- function vldt() {
- checkName();
- checkAge();
- checkEmail();
- checkPass();
- }
- </script>
- <form>
- Name : <input type="text" name="nm" id="nm"><br/>
- Age : <input type="text" name="ag" id="ag"><br/>
- Email ID : <input type="text" name="eml" id="eml"><br/>
- Password : <input type="text" name="pass" id="pass"><br/>
- Confirm Password : <input type="text" name="cpass" id="cpass"><br/>
- <input type="button" value="Validate" onclick="vldt()">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement