Find us on Google+ Kill the code: validation
Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

Sunday, 11 March 2012

Palindrome validation in Javascript

Preview :


New Web Project Enter a string :


Code :

<html>

    <head>

        <title>New Web Project</title>

    </head>

    <body>

     

     <script type="text/javascript">

      function pal() {

       var b;

       var a = document.getElementById('str');

       var c1 = a.value.length;

       var flag=0;

       for(b=0; b<c1/2;b++) {

        if(a.value.charAt(b)==a.value.charAt(--c1)) {

         flag=0;

        }

        else {

          flag=1;
          break;

        }

       }

       if(flag!=1) {

        document.getElementById("lbl").innerHTML = "The string is Palindrome";

        document.getElementById("fnt").style.color = "green";

       }

       else {

        document.getElementById("lbl").innerHTML = "The string is not Palindrome";

        document.getElementById("fnt").style.color = "red";

       }

       return;

      }

      

      function foc() {

       var a = document.getElementById("str");

       if(a.value == "enter string...") a.value = "";

       return;

      }

      function foc_lost() {

       var b = document.getElementById("str");

       if(b.value == "") b.value = "enter string...";

       return;

      }

     </script>

     

     

     

     

        Enter a string : <input type="text" name="string" id="str" value="enter string..." onfocus="return foc()" onblur="return foc_lost()"/>

        <input type="button" onclick="return pal()" value="Check"/><br />

        <font id="fnt"><label id="lbl"></label></font>

    </body>

</html>

Sunday, 4 March 2012

Set Password using JAVA

//This program lets you the password and access the data as soon as you type the //correct password..without pressing ENTER...





import java.awt.*;
import java.applet.*;
import java.awt.event.*;


/*
<applet code="password_setter" width=400 height=400>
</applet>
*/


public class password_setter extends Applet implements KeyListener {
String msg="";
String password="PASSWORD";  // Write your Password here....
char c;
boolean correct=false;
int i=0;
public void init() {
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke) {
showStatus("key Pressed.");
/*c=ke.getKeyChar();
check=true;
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}*/
//if(msg.equals(password)) showStatus("VALID PASSWORD.");
//showStatus("key Pressed.");
}
public void keyReleased(KeyEvent ke) {
if(msg.equals(password)) showStatus("VALID PASSWORD.");
}
public void keyTyped(KeyEvent ke) {
showStatus("Key Typed.");
//showStatus("Key Typed.");
c=ke.getKeyChar();
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}
if(msg.equals(password)) {
correct=true;
repaint();
showStatus("VALID PASSWORD.");
}
}
public void paint(Graphics g) {
if(correct) g.drawString("YOU HAVE ENTERED CORRECT PASSWORD.",40,40);
}
}