- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the email function with the question ID and the row number // 255 is the question ID and 1 is the row number which is the email field emailTest(255, 1); function emailTest(qID, inputNum) { // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Some vars - modify as required var emailMatch = /^[a-zA-Z0-9\_\-]+[a-zA-Z0-9\.\_\-]*@([a-zA-Z0-9\_\-]+\.)+([a-zA-Z]{2,4}|travel|museum)$/; var msg1 = 'Please enter a valid email address.'; // Test the input var emailInput = $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val(); if(emailInput != '' && !emailMatch.test(emailInput)) { alert(msg1); $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'pink' }); return false; } else { $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'' }); return true; } }); } }); </script>
function emailTest(qID, inputNum) { // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Some vars - modify as required var emailMatch = /^[a-zA-Z0-9\_\-]+[a-zA-Z0-9\.\_\-]*@([a-zA-Z0-9\_\-]+\.)+([a-zA-Z]{2,4}|travel|museum)$/; var msg1 = 'Please enter a valid email address.'; // Test the input var emailInput = $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val(); if(emailInput != '' && !emailMatch.test(emailInput)) { alert(msg1); $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'pink' }); return false; } else { $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'' }); return true; } }); }
<script type="text/javascript" charset="utf-8">$(document).ready(function() { // Call the email function with the question ID and the row number // 1 is the row number which is the email field emailTest({QID}, 1); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the email function with the text input emailTest("answer189137X255X33321"); function emailTest(inputID) { // Interrupt next/submit function $('#movenextbtn, #movesubmitbtn').click(function(){ // Some vars - modify as required var emailMatch = /^[a-zA-Z0-9\_\-]+[a-zA-Z0-9\.\_\-]*@([a-zA-Z0-9\_\-]+\.)+([a-zA-Z]{2,6})$/; var msg1 = 'Please enter a valid email address.'; // Test the input var emailInput = $("#"+inputID).val(); if(emailInput == "") { alert("No email present"); return false; } else if(emailInput != "" && !emailMatch.test(emailInput)) { alert(emailInput+' I'); $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'pink' }); return false; } else { alert(emailInput+' V'); $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').css({ 'background':'' }); return true; } }); } }); </script>