Comment valider US ZIP code à l'aide de jQuery plugin de Validation

Je suis en utilisant le plugin jQuery Validation pour la validation de mon formulaire.

Je veux valider le code postal comme par US Postal format :-

> 12345
> 12345-6789
> 12345 6789

Comme pour mon actuelle code son valider le code postal doit être au maximum de 5 et tous numériques.

Veuillez voir le code ci-dessous:

    <script src="~/Scripts/js/jquery.validate.js"></script>
<script>
$().ready(function () {
//validate signup form on keyup and submit
$("#locationSetup").validate({
rules: {
'Address.AddressStreet': "required",
'Address.City': "required",
'Address.State.Country.CountryIsoCode': "required",
'Address.State.SubnationalIsoCode': "required",
'Address.PostalCode': {
required: true,
minlength: 5,
maxlength: 5,
digits: true
}
},
messages: {
'Address.AddressStreet': "Please enter your Street Address!",
'Address.City': "Please select your City!",
'Address.State.Country.CountryIsoCode': "Please  select your Country!",
'Address.State.SubnationalIsoCode': "Please  select your State!",
'Address.PostalCode': {
required: "Please enter your Postal Code!",
minlength: "Your Postal Code must be 5 numbers!",
maxlength: "Your Postal Code must be 5 numbers!",
digits: "Your Postal Code must be 5 numbers!"
}
}
});
});
</script>
@using (Html.BeginForm(Model.Step.ToString(), "Provision", FormMethod.Post, new Dictionary<string, object> { { "id", "locationSetup" } }))
<table width="100%" id="locInfo">
<colgroup>
<col width="30%" />
<col />
</colgroup>
<tr>
<th><label>@AddressResource.COUNTRY_LABEL_TEXT:</label> <span class="redtext">(Required)</span></th>
<td>
@* @Html.HiddenFor(m => m.Address.State.Country.CountryIsoCode)*@
@Html.DropDownListFor(m => m.Address.State.Country.CountryIsoCode, ProvisioningHubProxy.GetCountriesList(),
htmlAttributes: new { @id = "Countries", @name = "Countries" })
</td>
</tr>
<tr>
<th> <label>@AddressResource.STATES_LABEL_TEXT:</label><span class="redtext">(Required)</span></th>
<td> @Html.DropDownListFor(m => m.Address.State.SubnationalIsoCode, ProvisioningHubProxy.GetStatesList(),
htmlAttributes: new { @id = "States", @name = "States" })</td>
</tr>
<tr>
<th><label>@AddressResource.CITY_LABEL_LABEL_TEXT:</label><span class="redtext">(Required)</span></th>
<td> @Html.TextBoxFor(m => m.Address.City, htmlAttributes: new { @name = "City", @id = "City" })</td>
</tr>
<tr>
<th> <label>@AddressResource.STREET_NAME_LABEL_TEXT:</label><span class="redtext">(Required)</span></th>
<td>@Html.TextBoxFor(m => m.Address.AddressStreet, htmlAttributes: new { @name = "StreetName", @id = "StreetName" })</td>
</tr>
<tr>
<th><label>@AddressResource.US_POSTAL_CODE_LABEL_TEXT:</label><span class="redtext">(Required)</span></th>
<td>@Html.TextBoxFor(m => m.Address.PostalCode, htmlAttributes: new { @name = "ZipCode", @id = "ZipCode", @required = "required" })</td>
</tr>
</table>

}

S'il vous plaît suggérer.

InformationsquelleAutor UID | 2013-09-25