page validation script - question

R

Raphael Gluck

HI

I am wondering if anyone can help me

I added a little script to a form page, so that a couple of fields have to
filled in. One contains an obligatory field for number data, one for regular
text.
However it seems that when a user will just enter a few spaces in the
required, they seem to be able to pass the validation script.

Here is the script, How should i modify it to exclude spaces?

Many thanks

Raphael

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number
between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
 
J

John

First of all: this is a ASP group.

Trim your field and if "" exit the function
Or if intr(field," ") 'two spaces' exit
Search the net for email validator scripts @ is not the only thing needed
for a valid script
 
J

Jeff Cochran

I am wondering if anyone can help me

Nope. This is an ASP forum, you're asking for help on a client-side
JavaScript script. Try a JavaScript forum.

Jeff
I added a little script to a form page, so that a couple of fields have to
filled in. One contains an obligatory field for number data, one for regular
text.
However it seems that when a user will just enter a few spaces in the
required, they seem to be able to pass the validation script.

Here is the script, How should i modify it to exclude spaces?

Many thanks

Raphael

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an
e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number
between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is
required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top