Friday, 27 May 2011

Popup using javascript

I want to share my knowledge regarding How to create a popup using javascript.

so first we will create html. Inside html we will need popup so, we will use DIV tag like below.
 <div id="popup">
        <div id="innerpopup" >
        <a href="javascript:close();" style="float:right;margin-right:10px;">Close</a><br/>Hello World

        </div>
 </div>

  In above we used two div.
  1. One div id is popup. This div actually cover the whole body so, we can click anywhere inside the body.
  2. Second div id is innerpopup. This div is actually used to display the content of popup.


  In above Div. We need to add some property to make it popup. So we need Css. Using Css we can define the property of div.
   #popup{
     position:absolute;
         width:100%;
         height:100%;
         display:none;
         top:0px;
         left:0px;
         background-color:#c0c0c0;
         opacity:0.8;
         filter: alpha(opacity = 80);
  }
  #innerpopup{
               width:400px;
               height:400px;
               margin-left:auto;
               margin-right:auto;
               margin-top:200px;
               background-color:#534435;
       }

    In above Css I define the popup width and height 100 percent so, it will cover the whole body
    and the important point i define the popup div as absolute to overlay the body.

    
    Now we need javascript to show and hide the popup.

    function show()
        {
               document.getElementById('popup').style.display ='inline';
               return;
        }
                     
        function close()
        {
               document.getElementById('popup').style.display ='none';
               return;
        }

so, Below is the whole code.

<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN">
<html>
 <head>
 <title> Pop Up </title>
 <style type="text/css">
  #popup{
     position:absolute;
         width:100%;
         height:100%;
         display:none;
         top:0px;
         left:0px;
         background-color:#c0c0c0;
         opacity:0.8;
         filter: alpha(opacity = 80);
  }
  #innerpopup{
               width:400px;
               height:400px;
               margin-left:auto;
               margin-right:auto;
               margin-top:200px;
               background-color:#534435;
       }
 </style>

 <script type="text/javascript">
           function show()
                       {
               document.getElementById('popup').style.display ='inline';
                               return;
                       }
                       function close()
                       {
                               document.getElementById('popup').style.display ='none';
                               return;
                       }
 </script>
 </head>

 <body>
       <div><a href="javascript:show()">Show</a></div>

       <div id="popup">
                                               <div id="innerpopup" ><a href="javascript:close();"
style="float:right;margin-right:10px;">Close</a>

                                               <br/>Hello World

                                               </div>
               </div>
 </body>
</html>

Verify Email Address in PHP


Hi Guys

          Today we are going to discuss about "How to verify email  in PHP". I read many articles regarding this issue.
     There is no perfect way that we can find out whether the email id is exist or not, but we can find out the existence of email domain.
     So, I want to share my knowledge with you.

     For a format validation we can use regular expression like
^[a-z0-9\.]+@[a-z0-9]+\.[a-z]{2,6}$
     In above pattern. I define that email can be alphanumeric  a-zA-Z and can be dot, numeric 0-9 and dot \. After that for domain also been checked same way as ID excluded dot so i had excluded.
So, extension also which can be alphabets from 2 to 6 character.

     To check the format we can use this regular expression in php like below.

     $txtemail='someone@domain.com';
     if(!ereg('^[a-zA-Z0-9\.]+@[a-zA-Z0-9]+\.[a-z]{2,6}$',$txtemail))
     {
               echo 'Invalid Email';

     }else{

                   //check for email domain


     }


     In above else parts we can confirm that the email format is Okay but domain may not be exist. So, to check that we can do the following things.
     In window system, we can use one dos command "nslookup" to check the domain. For example

     nslookup -type=MX gmail.com

     output:
       gmail.com mx preference = 20, mail exchange =
      alt2.gmail-smtp-in.l.google.com
       .................
       .................

     It means it is valid. Otherwise it will return some error.
     We can execute this command using exec() function like exec('nslookup -type=MX gmail.com');
     In this way at some extent we can check the validity of email.                   
     Thanks for giving yours time. Happy coding day....