hi im sure this is a basic question for you guys, but i need some help validating two fields so for example say one field has an input in i dont need to validate the other vice versa,
this is my HTML mark up and im focusing on the 2 fields from the last on which are "Where did you see the vacancy advertised?" and "Who recommended you"
<div id="ValidationSummary">
<%= Html.ValidationSummary("Please fix the following problems") %>
</div>
<% using (Html.BeginForm("job_application", "vacancies", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ %>
<div class="blue-border-form-details">
<h1>Personal Details</h1>
<fieldset>
<legend><label>* Title:</label><%=Html.DropDownList("Title", Model.TitleCollection())%></legend>
<legend><label>* First name:</label><%=Html.TextBox("FirstName", Model.FirstName, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend>
<legend><label>* Surname:</label><%=Html.TextBox("SurName", Model.SurName, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend>
<legend><label>* Email:</label><%=Html.TextBox("EmailAddress", Model.EmailAddress, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend>
<legend><label>* Mobile:</label><%=Html.TextBox("Mobilenumber", Model.Mobilenumber, new { maxlength = 11, size = "30", @class = "number", autocomplete = "off" })%></legend>
<legend><label>* Work Eligibility:</label> <%= Html.RadioButton("EligibleToWork", Model.EligibleToWork,true)%> I confirm that I am eligible to live and work in the UK</legend>
<legend><label> </label> <%= Html.RadioButton("NotEligibleToWork", Model.NotEligibleToWork,false)%> I am not currently eligible to live or work in the UK</legend>
<h1>Application Details</h1>
<div class="white-space"></div>
<legend><label>* Title:</label><%=Html.DropDownList("JobTitles", Model.VacanciesCollection())%></legend>
<legend><label>* Location:</label><%=Html.DropDownList("Locations", Model.LocationsCollection())%></legend>
<legend><label>* Attach CV:</label>How to upload your CV. Just click on the browse button below, find your CV in your<br /> files and add it. We can accept PDF or Word documents no larger than 500kb.
<br /></legend>
<legend><label> </label>Alternatively copy and paste your CV into the covering letter area.</legend>
<legend><label> </label><%= Html.TextBoxFor(m=> m.CV, new { type= "file" }) %><br /></legend>
<legend><label>Cover letter:</label><%= Html.TextArea("CoverLetter", Model.CoverLetter, new { maxlength = 2000, size = "300", @class = "text-area-enquiries", autocomplete = "off" })%></legend>
<legend><label class="large-label">Where did you see<br /> the vacancy Advertised?</label><%= Html.TextBox("VacancyAdvertised", Model.VacancyAdvertised, new { maxlength = 30, size = "30", autocomplete = "off" })%> </legend>
<legend><label class="large-label">Who recommended you?</label><%= Html.TextBox("RecommendedYou", Model.RecommendedYou, new { maxlength = 30, size = "30", autocomplete = "off" })%></legend>
<legend><label> </label><%= Html.CheckBox("CopyofApplication",Model.CopyofApplication)%> I wish to receive a copy of this application.</legend>
</fieldset>
</div>
<div class="white-space"></div>
<div>
<span class="margin-left"><a href="/vacancies/current-vacancies"><img src="/img/buttons/Back-to-Job-Description-Button.png" alt="Click to go back to Job Description" class="margin-left" title="Back to current vacancies"/></a></span>
<span><input type="submit" name="Submit" id="Submit" class="offset6 apply-now-button submit" value="Apply Now" title="Apply now | Send CV & application" runat="server" /></span>
</div>
<%= Html.ClientSideValidation("", typeof(BpdJobsModal.JobApplication))%>
<% } %>
</div>
This is the code in the modal again how can i combinded both of these in to one, make sure one of the two fields have a value in
[Required(ErrorMessage = " * Required")]
[RegularExpression(".{2,}", ErrorMessage = "Invalid Required Field")]
public string VacancyAdvertised { get; set; }
[Required(ErrorMessage = " * Required")]
[RegularExpression(".{2,}", ErrorMessage = "Invalid Required Field")]
public string RecommendedYou { get; set; }
Any help will be highly appreciated.
Thank you
Harrison.Sco...
Member
331 Points
456 Posts
How to validate two fields
Mar 19, 2012 09:41 AM|LINK
hi im sure this is a basic question for you guys, but i need some help validating two fields so for example say one field has an input in i dont need to validate the other vice versa,
this is my HTML mark up and im focusing on the 2 fields from the last on which are "Where did you see the vacancy advertised?" and "Who recommended you"
<div id="ValidationSummary"> <%= Html.ValidationSummary("Please fix the following problems") %> </div> <% using (Html.BeginForm("job_application", "vacancies", FormMethod.Post, new { enctype = "multipart/form-data" })) { %> <div class="blue-border-form-details"> <h1>Personal Details</h1> <fieldset> <legend><label>* Title:</label><%=Html.DropDownList("Title", Model.TitleCollection())%></legend> <legend><label>* First name:</label><%=Html.TextBox("FirstName", Model.FirstName, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend> <legend><label>* Surname:</label><%=Html.TextBox("SurName", Model.SurName, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend> <legend><label>* Email:</label><%=Html.TextBox("EmailAddress", Model.EmailAddress, new { maxlength = 50, size = "30", autocomplete = "off" })%></legend> <legend><label>* Mobile:</label><%=Html.TextBox("Mobilenumber", Model.Mobilenumber, new { maxlength = 11, size = "30", @class = "number", autocomplete = "off" })%></legend> <legend><label>* Work Eligibility:</label> <%= Html.RadioButton("EligibleToWork", Model.EligibleToWork,true)%> I confirm that I am eligible to live and work in the UK</legend> <legend><label> </label> <%= Html.RadioButton("NotEligibleToWork", Model.NotEligibleToWork,false)%> I am not currently eligible to live or work in the UK</legend> <h1>Application Details</h1> <div class="white-space"></div> <legend><label>* Title:</label><%=Html.DropDownList("JobTitles", Model.VacanciesCollection())%></legend> <legend><label>* Location:</label><%=Html.DropDownList("Locations", Model.LocationsCollection())%></legend> <legend><label>* Attach CV:</label>How to upload your CV. Just click on the browse button below, find your CV in your<br /> files and add it. We can accept PDF or Word documents no larger than 500kb. <br /></legend> <legend><label> </label>Alternatively copy and paste your CV into the covering letter area.</legend> <legend><label> </label><%= Html.TextBoxFor(m=> m.CV, new { type= "file" }) %><br /></legend> <legend><label>Cover letter:</label><%= Html.TextArea("CoverLetter", Model.CoverLetter, new { maxlength = 2000, size = "300", @class = "text-area-enquiries", autocomplete = "off" })%></legend> <legend><label class="large-label">Where did you see<br /> the vacancy Advertised?</label><%= Html.TextBox("VacancyAdvertised", Model.VacancyAdvertised, new { maxlength = 30, size = "30", autocomplete = "off" })%> </legend> <legend><label class="large-label">Who recommended you?</label><%= Html.TextBox("RecommendedYou", Model.RecommendedYou, new { maxlength = 30, size = "30", autocomplete = "off" })%></legend> <legend><label> </label><%= Html.CheckBox("CopyofApplication",Model.CopyofApplication)%> I wish to receive a copy of this application.</legend> </fieldset> </div> <div class="white-space"></div> <div> <span class="margin-left"><a href="/vacancies/current-vacancies"><img src="/img/buttons/Back-to-Job-Description-Button.png" alt="Click to go back to Job Description" class="margin-left" title="Back to current vacancies"/></a></span> <span><input type="submit" name="Submit" id="Submit" class="offset6 apply-now-button submit" value="Apply Now" title="Apply now | Send CV & application" runat="server" /></span> </div> <%= Html.ClientSideValidation("", typeof(BpdJobsModal.JobApplication))%> <% } %> </div> This is the code in the modal again how can i combinded both of these in to one, make sure one of the two fields have a value in [Required(ErrorMessage = " * Required")] [RegularExpression(".{2,}", ErrorMessage = "Invalid Required Field")] public string VacancyAdvertised { get; set; } [Required(ErrorMessage = " * Required")] [RegularExpression(".{2,}", ErrorMessage = "Invalid Required Field")] public string RecommendedYou { get; set; } Any help will be highly appreciated. Thank you