I am using the below code for validating email address using jquery.
I need to validate zipcode
using jquery
for US only. How can I do it using jquery
library.
This is my jQuery code:
$("#page1").on("pageinit", function() {
$("form").validate({
rules: {
email: {
required: true
},
password: {
required: true
}
},
errorPlacement: function(error, element) {
error.insertAfter(element.parent());
}
});
});
This is my HTML and 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 and (orientation: portrait) {
label.error {
margin-left: 0;
display: block;
}
}
@media screen and (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 anyone help me with this. Regards