Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI, i wan to validate to make sure the user enter Singapore zipcode.
May i know how to start?
Posted

Write a regex that conforms to the format, and apply it.
 
Share this answer
 
Comments
NooobieCoder 20-Jun-13 3:50am    
hi, can u teach me on how to start a regex?
You can start from here:
Regular-Expressions[^]

..and here is Basic Syntax Reference[^]
 
Share this answer
 
v2
XML
<html>
    <head>
        <script type="text/javascript">
            function PinVerify()
            {
                var strtext=document.getElementById("textbox").value;
                var index=strtext.length;
                //document.write(index);
                if(index==6)
                {
                    ///document.write("1111111");
                    if(strtext.charCodeAt(0)==48)
                    {
                        //document.write("222222");
                        alert("ZIP Cannot start from zero");
                    }
                    else
                    {
                        //document.write("222211111");
                        for(var i=1;i<index;i++)
                        {
                            //document.write("22222sdsdsd2");
                            var asciiValue=strtext.charCodeAt(i);
                            if(asciiValue>=48&&asciiValue<=57)
                            {
                                //document.write("22222256565656");
                                alert("Pin is Correct ");
                            }
                            else
                            {
                                alert("Only Numbers is allowed in Zip Code");
                            }
                        }
                    }
                }
                else
                {

                    alert("Pin code length can not be less than six");
                }
            }
        </script>
    </head>
        <body>
            Enter any value:<input type="text" id="textbox" />
            <button onClick="PinVerify()">Check For Zip Code</button>
    </body>
    </html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900