Thursday, December 27, 2012

JavaScript Form Validations

JavaScript is also used to validate the Form data of HTML pages before sending the data to server.

JavaScript can be validate any type of data.
(Ex. NULL values, Text, Numeric, Email, Date etc.)
For example take a HTML Form like below : ( Save this file as textData.php)
<form name="myForm" action="send_data.php" onsubmit="return validateForm()" method="post">
User Name : <input type="text" name="username">
First Name: <input type="text" name="firstname">
Password : <input type="password" name="password">
Mobile : <input type="text" name="mobile">
Gender : <select name="gender">
               <option value="">Select</option>
               <option value="male">Male</option>
               <option value="female">Female</option>
Date of Birth (yyyy/mm/dd) :  <input type="text" name="dateofbirth">
Email Id : <input type="text" name="emailid">
<input type="submit" name="submit" value="Submit">
Note: If you want to validate any data you should write in the below function only as per the above html code. You can change the function names and field names as per your needs.
function validateForm()
      //write below code here if required
      return true;
To Test Required Fields :
     This script is used to check the username is empty or not, if empty it will promt an alertbox to user with message "User Name Required" and it will focus on the particular username field.
if( document.myForm.username.value == null || document.myForm.username.value == "" )
      alert("User Name Required");
      return false;
To Test Text Data or Digits(Numbers) Only:
     This script is used to check the field value is text or digits, based on the condition it will prompt an error, other wise ignores.
Here we need to create two expressions based on our requirements to test whether the field value is Text or Number.
var numbexp = /^[0-9]+$/;
var charexp = /^[a-zA-Z]+$/;

if( !document.myForm.firstname.value.match(charexp) )
      alert("Please Enter Text Data Only");
      document.myForm.firstname.value = "";  //This is used to remove the data from the field
     return false;

if( ! )
     alert("Please Enter Numbers Only"); = "";  //This is used to remove the data from the field;
     return false;
To Test Email Fields :
     This script is used to check the field contains value is valid email or not, it will accept the value only if contains a '@' symbol, a '.' symbol and 2 to 3 charactors after dot symbol. Other wise prompt alert to user.
var emailexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if( !document.myForm.emailid.value.match(emailexp) )
     alert("Please Enter Valid Email Id");
     document.myForm.emailid.value = "";
     return false;
To Check Length of the Field :
     This script used to check the length of the field value, if it has more than 10 characters it will show an alert message, other wise it will ignore.
if( document.myForm.username.value.length >= 10 )
     alert("Maximum 10 Characters only");
     document.myForm.username.value = "";
     return false;
     This script is used to validate a value between a given range i.e, minimun and maximum value. Assume username should be Minimum 6 Characters and Maximum 12 Characters
if( document.myForm.username.value.length < 6 || document.myForm.username.value.length >12 )
     alert("User Name should contain min 6 characters and max 12 characters");
   document.myForm.username.value = "";
   return false;
To Test Date Format :
     This script is used to check the date format according to your needs. using this expression we can validate the date field mostly.
var dateexp = /^[0-9]{4}\/(0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])+$/;
if( document.myForm.dateofbirth.value.match(dateexp) )
     alert("Invalid Date Format... Correct it");
     return false;
To Test Select Boxes :
     This script is used to check the select box is selected or not.
if(document.myForm.gender.selectedIndex == 0)
      alert("Please Select Gender");
      return false;

Tuesday, December 25, 2012

Installing and Configuring PHP and MySql with XAMPP in Windows

Xampp is a free web server that interprets php and perl programming language. It's mainly used to test the web application during the development.

Downloading xampp:

Go to the official website of xampp "" and download the xampp installer.

Installing the xampp:

  • Click on the downloaded xampp installer.
  • A Warning window will opens, click yes
  • Select a language and click OK
  • In the xampp installation wizard click next
  • Click browse, select local disk C or D(Your wish) to install xampp and click OK
  • Click Next
  • Check the buttons for install Apache, MySql and Filezilla as service
  • Click Install
  • Wait till the installation process is complete then click finish
  • Wait for these messages which shows "Congratulations! The installation was successful! Start XAMPP Control Panel now?" and click Yes and OK
  • Then xampp control panel will be opened with running Apache, MySql and FileZilla Services.

If you want to access Xampp control panel manually you can open it from C: or D: Drive >> xampp >> double click on xampp-control file.

Test the Xampp Installation:

  • Open browser and type this url "http://localhost"
  • Choose a language
  • After choosing a language, you should get a page which displays with a left menu of xampp
  • Click on Status on left menu of xampp page to check the status of xampp

Creating a PHP file:

Open Notepad and write the below code:


Save the above file in the xampp installed directory.
Example: "C:\xampp\htdocs\index.php"

Executing the PHP file:

Open the browser and type the below URL to execute the above saved php file.

Then the complete information about the installed softwares of xampp will be shown in the html page. here you can check the status of all the things.

Now you can write and execute any number php files in the htdocs.

Happy Coading...

Installation and Environment Setup for Java

Follow the below steps to set up the environment of Java.

     Java SE is free software to download from the following URL You can choose a version based on your operating system.

     Follow the instructions to run the .exe to install Java on your machine. Once you installed Java on your machine, you should set environment variables to point to correct installation directories.

Setting up the path for windows 2000/XP/7:

Assuming you have installed Java in c:\Program Files\Java\jdk directory:

  • Right-click on 'My Computer' and select 'Properties'.
  • Click on 'Environment Variables' button under the 'Advanced' tab.
  • Now alter the 'Path' variable so that it also contains the path to the Java executable.
    Example: if the path is set to some other path then append the below path to existed path.         ";C:\Program Files\java\jdk\bin".

Setting up the path for Linux, UNIX, Solaris, FreeBSD:

Environment variable PATH should be set to point to where the java binaries have been installed. Refer to your shell documentation if you have trouble doing this.

Example, if you use bash as your shell, then you would add the following line to the end of your '.bashrc:export PATH=/path/to/java:$PATH'

Most Popular Java Editors:

1. Notepad
2. Netbeans
3. Eclips

Creating First Application:

Assume your first application MyApp, will display "Hello World".

Source Code:

public class MyApp {

public static void main(String args[]) {
System.out.println("Hello World"); //prints Hello World

Note: While Compiling and Executing any Java Programs program names are case-sensitive.

Executing the Java Program:

Create a source file(creating .java file): Source file contains the required code, written in Java programming language. You can use any text editor to create and edit source files.

Compile the source file(it will create a .class file): Java programming language compiler (javac) takes your source file and translates its text into instructions that the Java virtual machine can understand. The instructions contained within this file are known as bytecodes.

Run the program: The Java application launcher tool (java) uses the Java virtual machine to run your application.

How to Write, Save, Write, Compile and Run a Java Program:

1. Open Text Editor and write code and save the file as
2. Open command prompt window and go to the directory where you saved the class. 
Example C:\
3. Type 'javac' and press enter to compile your code. If there are no errors in your code the command prompt will take you to the next line.(Assumption: The path variable is set).
4. Now type 'java MyApp' to run your program.
5. You will be able to see 'Hello World' printed on the window.

Now you can write and execute any number of programs.... Enjoy writing.

Thursday, December 20, 2012

Sharing a Folder in Linux Ubuntu 12.04

One of the most common ways to share a folder on Ubuntu system is to configure Samba File Server. These Steps will help to configure Samba server to share files and folders in network.

1. First install the samba package from terminal by typing the following command
sudo apt-get install samba

after completion of successful installation we can share a folder directly by right click on a folder and select share folder option.

If you want to provide a secure access to that folder then we need to change the Samba server configuration file.
The Samba configuration file is located in /etc/samba/smb.conf.
Edit the pairs in the [global] section of /etc/samba/smb.conf file:
  workgroup = EXAMPLE
  security = user
Uncomment the security parameter which is commented by default and also change EXAMPLE to match your environment.

Create a new section at the bottom of the file like this:

   comment = Ubuntu File Server Share
   path = /svr/samba/share
   browsable = yes
   guest ok = yes
   read only = no
   create mask = 0755

comment: a short description of the shared file.

path: path to the directory to share.

In this example i use /svr/samba/sharefoldername because, /svr is where site-specific data should be served. Samba shares can be placed anywhere on the filesystem as long as the permissions are correct, but adhering to standards is recommended.

browsable: enables Windows users to browse the shared directory and files using Windows Explorer.

guest ok: allow clients to connect to the shared folder without entering a password.

read only: determines if the share folder is read only or if write privileges are granted. if the value is no then write privileges are allowed, if the value is yes then the privileges are set to read only.

create mask: determines the permissions to new files  will have when created.

Now the Samba Server is configured, then we need to create the directory and change the permissions.
Open Terminal and type the following commands:
sudo mkdir -p /srv/samba/share
sudo chown nobody.nogroup /srv/samba/share/

The -p switch tells mkdir to create the entire directory tree if it doesn't exist.

Finally restart the samba services to enable the new configuration:

sudo restart smbd
sudo restart nmbd

Connecting Ubuntu 12.04 via Remote from Windows

Connecting to the Ubuntu 12.04 Desktop from Windows is a easy way by following below steps. This can be done using XRDP server package installation.

1. Open the Terminal in Ubuntu system and type the below command
sudo apt-get install xrdp
2.  After completion of the installation process, open the Windows 7 system and Go to Start - and click on Remote Desktop Connection

3. Enter computer name or hostname or IP address of  ubuntu system and click on connect

3. When prompted, type your Ubuntu Username and Password to connect

4. Finally the Ubuntu Desktop will appear on your Windows System.

Note: While connecting to the system if you face any problem then type this below commands and try again

cd /home/youruser
echo "gnome-session --session=ubuntu-2d" > .xsession
sudo /etc/init.d/xrdp restart
Or install gnome session fallback

sudo apt-get install gnome-session-fallback

Sunday, December 16, 2012

Steps to install Kannel SMS Gateway with SQLBox

Kannel :
Kannel is a compact and very powerful open source WAP and SMS gateway,WAP is used for Push service indications and mobile Internet connectivity.
Wireless Application Protocol is a technical standard for accessing information over a mobile wireless network. WAP means a protocol that are used to connect wireless GPRS OR GSM with web browser by sending encoded message to mobile. By this web browser get the information of mobile device and start sending messages or emails through network.
Steps to install kannel with sqlbox:
1. To install kannel we need to install this essencial requirements.
Warning : run command with sudo user
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install bison
sudo apt-get install libmysqld-dev

sudo apt-get install libxml2-dev
2. Download gateway stable release version 1.4.3.
3. Extract gateway folder in any directory of your system. 
$ tar xfvz gateway-1.4.3.tar.gz
4. Goto gateway folder.
$ cd gateway-1.4.3/
5. Configure
The below command makes the shell run the script named ‘ configure ‘ which exists in the current directory. The configure script basically consists of many lines which are used to check some details about the machine on which the software is going to be installed. This script checks for lots of dependencies on your system. wait for the completion of the process.

$ ./configure --with-mysql
6. make
make command used to perform all necessary re-compilations. You can use make with any programming language whose compiler can be

run with a shell command. make command is used when we want to run any project which needs compilation of files.

$ make
7. make install
The install section happens to be only a part where the executables and other required files created during the last step (i.e. make) are copied into the required final directories on your machine. E.g. the executable that the user runs may be copied to the /usr/local/bin so that all users are able to run the software. Similarly all the other files are also copied to the standard directories in Linux. Remember that when you ran make, all the executables were created in the temporary directory where you had unzipped your original tarball. So when you run make install, these executables are copied to the final directories.

$ make install

8. Download sqlbox by typing the below command line.

$ svn co sqlbox

9. Extract sqlbox folder in gateway folder which was downloaded before. Run below mentioned commands to install sqlbox.

$cd sqlbox
$ ./configure
$ make

$ make install

Kannel installation with sqlbox is completed.

Now we need to configure both kannel.conf file and sqlbox.conf.
1. Copy this below code and paste in your /etc/kannel/kannel.conf file and change the details according to your needs.
group = core
admin-port = 13000
smsbox-port = 13001
admin-password = *****
status-password = *****
admin-allow-ip = "*.*.*.*"
wdp-interface-name = "*"
log-file = "/var/log/kannel/bearerbox.log"
#store-file = "/var/log/kannel/"
log-level = 0
box-deny-ip = "*.*.*.*"
box-allow-ip = "*.*.*.*"

group = smsbox
bearerbox-host = localhost
sendsms-port = 13013
bearerbox-port = 13001
sendsms-chars = "0123456789 +-"
global-sender = +91number
log-file = "/var/log/kannel/smsbox.log"
log-level = 0

group = sendsms-user
username = usernameToSendSms
password = passwordToSendSms
default-smsc = SMSC-ID
user-allow-ip ="*.*.*.*"

#mysql connection
group = mysql-connection
id = sqlbox-db
host = localhost
username = root
password = passwordOfMysql
database = dataBaseName
max-connections = 10

#mysql connection
group = mysql-connection
id = mydlr
host = localhost
username = root
password = passwordOfMysql
database = dataBaseName
max-connections = 10

group = dlr-db
id = mydlr

# SMSC Fake
group = smsc
smsc = fake
port = 10000
connect-allow-ip =

# SMS SERVICE black-list
#group = sms-service
#keyword = black
#text = "You are not allowed to use this service, Go away!"
#catch-all = true

group = smsc
smsc-id = idForSmsc
smsc = smpp
host = **.**.**.**
port = portnumber
receive-port = 16400
smsc-username = username
smsc-password = password
system-type = type
system-id = id
address-range = ""

group = sms-service
keyword = default
send-sender = true
get-url = "http://localhost/receivesms?phone=%p&text=%a"

# there should be default always
#group = sms-service
#keyword = default
#text = "No service specified. "

Note: Remove # symbols if you need and change the value for that according to your requirement.

2. Copy the below code and paste in /etc/kannel/sqlbox.conf file and change the details according to your requirement.
group = sqlbox
id = sqlbox-db
smsbox-id = sqlbox
global-sender = ""
bearerbox-host = localhost
bearerbox-port = 13001
smsbox-port = 13002
smsbox-port-ssl = false
sql-log-table = sent_sms
sql-insert-table = send_sms
#log-file = "/var/log/kannel/kannel-sqlbox.log"
#log-level = 0
#ssl-client-certkey-file = ""
#ssl-server-cert-file = ""
#ssl-server-key-file = ""
#ssl-trusted-ca-file = ""

# Database connection examples. Please uncomment as needed
# Example MYSQL Connection
group = mysql-connection
id = sqlbox-db
host = localhost
username = root
password = passwordOfMysql
database = dataBase

# Example ORACLE Connection
#group = oracle-connection
#id = sqlbox-db
#username = myuser
#password = mypass
#tnsname = //localhost:1521/XE

# Example POSTGRESQL Connection
#group = pgsql-connection
#id = sqlbox-db
#id = sqlbox-db
#username = myuser
#password = mypass
#database = kannel
#host = localhost

# Example SDB Connection with some database URL examples
# *** Note: Uncomment only _one_ "url" line ***
#group = sdb-connection
#id = sqlbox-db
#url = mysql:host=localhost:db=kannel:uid=myuser:pwd=mypass
#url = sqlite:db=/path/to/kannel.db
#url = sqlite3:db=/path/to/kannel3.db

# Example SQLITE 2 Connection
#group = sqlite-connection
#id = sqlbox-db
#database = /path/to/kannel.db
#max-connections = 1

# Example SQLITE 3 Connection
#group = sqlite3-connection
#id = sqlbox-db
#database = /path/to/kannel.db
#max-connections = 1

Installation and Configuration is completed now. We should run the Bearerbox, Sqlbox and Smsbox to send a sms from the kannel using smpp account.

Note: Open 3 Termials for 3 boxes individually
Starting the Bearerbox: (type this command in terminal as super user)
bearerbox -v 0 /etc/kannel/kannel.conf
Starting the Sqlbox: (type this command in terminal as super user)
sqlbox -v 0 /etc/kannel/sqlbox.conf
Stargin the Smsbox:  (type this command in terminal as super user)
smsbox -v 0 /etc/kannel/kannel.conf
if boxes are running properly without any errors then you succefully installed kannel with sqlbox. if you got any errors you can post a comment here....
Sending first sms:
Open MySql or PhpMyAdmin and login with your details.
Then open the send_sms table and insert a record.
Note: No need to insert all the fields. Mandatory fields are 
1. Sender
2. Reciever
3. Text (Message)
4. SMSC_ID (which is used in kannel.conf file to identify the smsc_id)
5. Account (Username of smsc)
Then automatically the message goes to the particular number.
If you want to check the status of your messages open browser and type the url in the address bar
(here status-password is the password which is given in the kannel.conf file)