| ||||||
|
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:
|