I am trying to implement a validation process in which students must include specific keywords in their lesson summaries before submission. The current regex I have works well, except when the student creates a new paragraph using the enter key.
/^(?=.*\bmodel|models\b)(?=.*\btheory|theories\b)(?=.*\blaw|laws\b)(?=.*\bscale\b)/i;
I have tried modifying the regex to allow for reading across line breaks, but so far I have not been successful. Any guidance on what I might be doing wrong would be greatly appreciated as I am still learning in this area. Many thanks!
var ck_summary = /^(?=.[\S\s]*\bmodel|models\b)(?=.[\S\s]*\btheory|theories\b)(?=.[\S\s]*\blaw|laws\b)(?=.[\S\s]*\bscale\b)/i;
As a beginner in this field, I am eager to understand and improve my coding skills. Below is the script I am using for summary validation...
var ck_studentid = /^[0-9]{6,6}$/;
var ck_summary = /^(?=.[\S\s]*\bmodel|models\b)(?=.[\S\s]*\btheory|theories\b)(?=.[\S\s]*\blaw|laws\b)(?=.[\S\s]*\bscale\b)/i;
function validate(sumform){
var studentid = sumform.studentid.value;
var summary = sumform.summary.value;
var errors = [];
if (!ck_studentid.test(studentid)) {
errors[errors.length] = "Check your Student ID";
}
if (!ck_summary.test(summary)) {
errors[errors.length] = "Make sure you used all of the vocabulary terms AND you spelled them correctly.";
}
if (errors.length > 0) {
reportErrors(errors);
return false;
}
return true;
}
function reportErrors(errors){
var msg = "Uh oh, looks like we have a problem...\n";
for (var i = 0; i<errors.length; i++) {
var numError = i + 1;
msg += "\n" + numError + ". " + errors[i];
}
alert(msg);
}