javascript - How to validate US zip code using jquery -
i using below code validating email address using jquery.
i need validate zipcode
using jquery
only. how can using jquery
library.
this jquery code:
$("#page1").on("pageinit", function() { $("form").validate({ rules: { email: { required: true }, password: { required: true } }, errorplacement: function(error, element) { error.insertafter(element.parent()); } }); });
this html , css:
label.error { color: red; font-size: 16px; font-weight: normal; line-height: 1.4; margin-top: 0.5em; width: 100%; float: none; } @media screen , (orientation: portrait) { label.error { margin-left: 0; display: block; } } @media screen , (orientation: landscape) { label.error { display: inline-block; margin-left: 22%; } } em { color: red; font-weight: bold; padding-right: .25em; } </style> </head> <body> <div id="page1" data-role="page"> <div data-role="header">
<body> <div id="page1" data-role="page"> <div data-role="header"> <h1>welcome</h1> </div> <div data-role="content"> <form method="get"> <div data-role="fieldcontain"> <label for="email">email:</label> <input type="email" name="email" id="email"> </div> <div data-role="fieldcontain"> <label for="password">password:</label> <input type="password" name="password" id="password"> </div> <div data-role="fieldcontain"> <label for="zip">zipcode:</label> <input type="text" name="zip" id="zip"> </div> <input data-role="submit" type="submit" value="login"> </form> </div> </div> </body>
can me this. regards
you use regex /(^\d{5}$)|(^\d{5}-\d{4}$)/
var isvalid=/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(yourvalue); if(!isvalid) alert("not valid");
Comments
Post a Comment