javascript validation for mixed form

L

ll

Hi,
I am working with a page that has both cfform elements and 'plain
html' form elements. In particular, I am needing to validate my
textarea form field and my email text field. On one of my html pages,
I have been using a great javascript validation script; however, I am
wondering if I can use that in a coldfusion page? I've included the
javascript I'd been using before.
Thanks for any help you can provide,
Regards,
Louis


In the cfform tag, I included this call:
<cfform action="#cgi.script_name#" method="Post" name="NewItemForm"
onSubmit="return checkWholeForm(this)" >


The javascript in the head is listed below:
-----
<script language="JavaScript">
// news headline/email subject
function checkEmailSubject (strng) {
var error="";
if (strng == "") {
error = "Please enter an Email Subject/News Headline.\n\n";
}

// news/email content
function checkContent (strng) {
var error="";
if (strng == "") {
error = "Please enter Email/News Content.\n\n";
}

// email
function checkEmail (strng) {
var error="";
if (strng == "") {
error = "Please enter your email address.\n\n";
}

//filter for ou/ouhsc domains
var emailFilter2=/.@(ou|ouhsc)\.edu$/i
if (!(emailFilter2.test(strng))) {
error="Please enter a valid email address with either ou or ouhsc
domain.\n\n";
}
//end domain filter

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) {
error = "Please enter a valid email address.\n\n";
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
error = "The email address contains illegal characters.\n
\n";
}

}
return error;
}


<!-- Begin check form script, which refers to above -->

function checkWholeForm(NewItemForm) {
var why = "";
why += checkEmail(NewItemForm.Email1.value);
why += checkEmailSubject(NewItemForm.EmailSubject.value);
why += checkContent(NewItemForm.Content.value);
if (why != "") {
alert(why);
return false;
}
return true;
}
// -->
</script>
<!-- End form validation script -->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top