I'm creating a small jquery mobile project and have decided to use jqueryvalidation http://jqueryvalidation.org/ for form validation. I have a popup box where the user enters a number which is either their phone or email (unfortunately this has to stay like this because of the database) so I want to use the validation to say that the field must either contain email: or digits:.
Do you know if this is possible? Or a workround? Using depends: won't work either in this case as there is no conditional that will work on every database (the primary phone/email will not always be filled).
<form id='addNumber' action ='' method='post' data-ajax='false'>
<div class="ui-field-contain">
<label for="phoneType">Type</label>
<select name="phoneType" id="phoneType" data-native-menu="false">
<?php echo $phoneInnerOptions; ?>
</select>
</div>
<div class="ui-field-contain">
<label for="phoneNumber">Number</label>
<input type="text" name="phoneNumber" id="phoneNumber" value="">
</div>
<div class="ui-field-contain">
<label for="primary">Primary Contact</label>
<select name="primary" id="primary" data-native-menu="false" >
<option value="1">Primary Phone</option>
<option value="2">Primary Email</option>
<option value="3"></option>
</select>
</div>
<div class='ui-grid-a'>
<div class='ui-block-a'><input type='submit' value='Update' class='ui-btn ui-btn-inline' data-transition='pop' /></div>
<div class='ui-block-b'><a href='#' id="addNumberReset" class='ui-btn' data-rel='back' data-transition='pop'>Cancel</a></div>
</div>
</form>
And the current validation:
$().ready(function() {
// validate add number form
$("#addNumber").validate({
errorPlacement: function(error, element) {
error.insertAfter(element.parent()); // <- make sure the error message appears after parent element (after textbox!)
},
rules: {
phoneNumber: "required",
},
messages: {
phoneNumber: "Please enter a valid phone or email",
}
}); //end validate
});// end function
Any help or advise with this one would be appreciated :)