Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 5 February 2015
Keywords : JQuery Postal code number validation,Postal code number validation using JQuery,Postal code number validation

Validate Postal Code Number Using JQuery

Postal Code Number Validation In JQuery Using Regular Expressions

This Jquery Code Check if the Postal Code number is valid. If the Postal Code Number is not valid the text is replaced with a message "Invalid Postal Code Number" in the text Placeholder.

Expected Output

Code Snippet

    <script src=""></script>
    <script type="text/javascript">

        $.fn.isPostalCodeNumber = function (options) {
            intRegex = /^[0-9]{1,4}$/;
           postalcodeNumber = this.val();
            if ((postalcodeNumber.length != 10) || (!intRegex.test(postalcodeNumber))) {
                this.attr("placeholder", "Invalid Postal Code Number");
                return false;
            return true;

        function validate() {
            return false;
    <input type="text" id="checkPostalCodeNumber" value="ASDFG77" />
    <input type="button" onclick="return validate()"  value="Validate"/>

Download Sample Code

Click Right Click here and select "save link as" to download Sample Code. Click here To View sample code working

Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.