I am using xVal to validate my forms in asp.net MVC 1.0
Not sure why my regular expression isn't validating correctly.
- It does NOT validate with an empty value
- It does NOT validate with the value of "1", "12", "123", or "1234"
- It validates with the value of "12345"
- It validates with the value of "12345 "
- It validates with the value of "12345 -"
- It validates with the value of "12345 -1"
- It validates with the value of "12345 -12" ... etc
For a zip code I expect one of the two patterns:
12345
or 12345 -1234
Here are the two regex I tried:
(\d{5})((( -)(\d{4}))?)
(\d{5})|(\d{5} -\d{4})
Here is my MetaData class for xVal
[MetadataType(typeof(TIDProfileMetadata))]
public class TIDProfileStep
{
public class TIDProfileMetadata
{
[Required(ErrorMessage = " [Required] ")]
[RegularExpression(@"(\d{5})|(\d{5} -\d{4})", ErrorMessage = " Invalid Zip ")]
public string Zip { get; set; }
}
}
Here is my aspx page:
<% Html.BeginForm("Edit", "Profile", FormMethod.Post); %>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<h6>Zip:</h6>
</td>
<td>
<%= Html.TextBox("Profile.Zip")%>
</td>
</tr>
<tr>
<td>
<input type="submit"/>
</td>
</tr>
</table>
<% Html.EndForm(); %>
<% Html.Telerik().ScriptRegistrar()
.OnDocumentReady(() =>
{ %>
<%= Html.ClientSideValidation<TIDProfileStep>("Profile").SuppressScriptTags() %>
<% }); %>