CancelImage Upload

Postcode Validation: Indian Postal Index Number with JavaScript Regular Expressions

Indian postal index numbers are 6 digit numbers, and therefore putting together a Regular Expressions statement to validate them does not require to much work. Our statement will consist of two parts, the first consisisting of numbers ranging from 1-9, the second, consisting of 5 digits will be 0-9:

^([1-9])([0-9]){5}$

Below you will first find a JavaScript example code for validating Indian Postcodes, followed by a table containing the individaul Postal Circles and the corresponding first two digits:

<html>
<head>
<title>India Postcode Validation with JavaScript</title>

<script language="JavaScript">

function postcode_validate(zipcode)
{

    var regPostcode = /^([1-9])([0-9]){5}$/;

    obj = document.getElementById("status");

    if(regPostcode.test(zipcode) == false)
    {

        obj.innerHTML = "Postcode is not yet valid.";

    }
    else
    {

        obj.innerHTML = "Your India Postal Index Number is valid!";

    }

}

</script>

<style type="text/css">
<!--
body {
background:#CCCCFF;
}

div {
width: 100%;
text-align: center;
margin-top:150px;
}

span {
color: #000099;
font: 8pt verdana;
font-weight:bold;
text-decoration:none;
}

input {
color: #000000;
background: #F8F8F8;
border: 1px solid #353535;
width:250px;
font: 8pt verdana;
font-weight:normal;
text-decoration:none;
margin-top:5px;
}
-->
</style>
</head>
<body>

<div>
<span id="status">Please enter a valid postcode.</span><br>
<input type="text" name="postcode" onkeyup="postcode_validate(this.value);">
</div>

</body>
</html>

Here is an index of the various area codes, consisting of the first two digits. They are not of importance for our example as such, but could be of value for interpreting the input, or if you want to include stricter validation guidelines:
Postal CircleCorresponding First Two Digits
Delhi11
Haryana12 13
Punjab14-16
Himachal Pradesh17
Jammu & Kashmir18-19
Uttar Pradesh20-28
Rajasthan30-34
Gujarat36-39
Maharastra40-44
Madhya Pradesh45-49
Andhra Pradesh50-53
Karnataka56-59
Tamil Nadu60-64
Kerala67-69
West Bengal70-74
Orissa75-77
Assam78
North Eastern India79
Bihar and Jharkhand80-85


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com