I have textbox and drop-down I want to compare both the values and trigger alert every time when something changes and both are not equal. Suppose If I select six from my drop-down and If I don't enter 6 numbers in my textbox it should trigger alert and also I should get alert if I enter 6 numbers in textbox and select 12 numbers in my drop-down. How do I write single function to check both the conditions?
$(document).ready(function () {
$('#myDropdown').change(function () {
var sixNumeric = /^[0-9]{6}$/;
var twelveNumeric = /^.[0-9]{12}$/;
var dropdown = $("#myDropdown").val();
var textval = $("#myInput").val();
if (myDropdown == 'text' ) {
alert("enter only text");
}
if (dropdown == "six") {
if (sixNumeric.test(textval) ==false ) {
alert("Must be 6 numeric");
}
}
if (dropdown == "tweleve") {
if (twelveNumeric.test(textval) ==false ) {
alert("Must be 12 numeric");
}
}
});
<select id="myDropdown">
<option value="six">SixNumeric</option>
<option value="tweleve">TwelveNumeric</option>
</select>
<input type="text" id="myInput" value="" />