I use the following code to check if all form fields are not empty before the submit button is activated.
<script type="text/javascript">
function checkForm() {
var cansubmit = false;
$('form input[type="text"]').each(function (index, element) {
if (element.value == "") {
cansubmit = true;
}
});
document.getElementById("uploadButton").disabled = cansubmit;
}
</script>
How can I edit this code so it checks if the email field contains an email address before the submit button is activated?
UPDATE
I changed the code to this and it seems to work. It checks if it contains @
(and not as the first symbol) and .
(and not as the third symbol).
Is this a logical code or should it be easier?
<script type="text/javascript">
function checkForm() {
var cansubmit = false;
$('form input[type="text"]').each(function (index, element) {
if (element.value == "") {
cansubmit = true;
}
});
$('form input[type="email"]').each(function (index, element) {
if (element.value.indexOf("@") <= 0) {
cansubmit = true;
}
else if (element.value.indexOf(".") <= 2) {
cansubmit = true;
}
});
document.getElementById("uploadButton").disabled = cansubmit;
}
</script>