help modifying script to validate text field

M

Mike

I'm using a script provided by e-mailanywhere, it's a little too big
for me.
There's 1 text field and 1 password field in a form.
OnSubmit, I would like both fields to be validated to look for invalid
digits (~`!#$%^&*()+=?/). This is not working yet, I don't know why.
In addition, I would like both fields to require from 1 to 12 digits
for submition to continue.
The text field also Lowers Case, can you tell me how to do the same on
password field?
I would like to ask that if you reply, please write exactly how you
would modify the script, it's of a lot more help. Thanks in advance
for all replies, below is the page I have:

<html>
<head>
<title>Chech Your Email</title>
<script language="JavaScript">
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function trimspace(str)
{
temp_str = "";
for (i=0; i<str.length; i++) {
c = str.charAt(i);
if (c != " "){
temp_str = str.substring(i, str.length);
break;
}
}

for (i=temp_str.length-1; i>=0; i--) {
c = temp_str.charAt(i);
if (c != " ") {
temp_str = temp_str.substring(0, i+1);
break;
}
}

return temp_str;
}

function validate_str(str) {
var ok = 1;
if (str.indexOf("~") != -1)
ok = 0;
if (str.indexOf("`") != -1)
ok = 0;
if (str.indexOf("!") != -1)
ok = 0;
if (str.indexOf("#") != -1)
ok = 0;
if (str.indexOf('$') != -1)
ok = 0;
if (str.indexOf("%") != -1)
ok = 0;
if (str.indexOf("^") != -1)
ok = 0;
if (str.indexOf("&") != -1)
ok = 0;
if (str.indexOf("*") != -1)
ok = 0;
if (str.indexOf("(") != -1)
ok = 0;
if (str.indexOf(")") != -1)
ok = 0;
if (str.indexOf("+") != -1)
ok = 0;
if (str.indexOf("=") != -1)
ok = 0;
if (str.indexOf("?") != -1)
ok = 0;
if (str.indexOf("/") != -1)
ok = 0;

if (ok == 0) {
alert("Invalid input - cannot contain ~ ` ! # $ % ^ & * ( ) + = ?
/");
return -1;

} else
return 1;
}

function update(theform) {
var email = trimspace(document.forms[theform].emailaddress.value);
if (email == "") {
alert("Please Enter Your User Name.");
return;
}

if (email.indexOf("@") == -1) {

email = email + "@somepage.com"
}
else if (email.indexOf(".") == -1) {
alert("Please Enter a Valid Email Address.");
return;
}

document.forms[theform].emailaddress.value = email;
document.forms[theform].submit();
}

function lemmein(keypressed){
var key;

if (document.all) {
key=window.event.keyCode;
} else {
key=keypressed.which;
};
if (key==13) {
update("email");
}
}

function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ?
event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements)
break;
i = (i + 1) % field.form.elements.length;
field.form.elements.focus();
return false;
}
else
return true;
}

// -->
</script>
</head>
<body>
<form name="email" method="POST"
action="http://www.e-mailanywhere.com/servlet/emailLogin">
<input type="hidden" name="logoutURL" value="http://www.somepage.com">
<input type="text" name="emailaddress" size="20" value=""
onkeypress="return handleEnter(this, event)"
onChange="javascript:this.value=this.value.toLowerCase();">
<input type="password" name="password" onkeypress="return
handleEnter(this, event)" size="19" onBlur="">
<input type="button" onClick='javascript:update("email");' value="Log
In">
<br>Powered by <a title="e-mailanywhere.com"
href="http://www.e-mailanywhere.com">e-mailanywhere</a>.
</form>
</body>
</html>
 
L

Lasse Reichstein Nielsen

Janwillem Borleffs said:
Be aware that the email address validation is rudimentary, anything that
consists of characters a-z, digits and dots, with an at-sign inbetween is
considered valid.

Just a comment because it sounds like you think the e-mail validation
accepts too much. It's probably both too much and too too little.

While it might be problematic to accept foo@bar, it's the false
negatives that are really disasterous, e.g., (e-mail address removed) or
"Mr. Foo Bar"@example.com (both of which are perfectly good e-mail
adresses).

/L
 
J

Janwillem Borleffs

Lasse Reichstein Nielsen said:
Just a comment because it sounds like you think the e-mail validation
accepts too much. It's probably both too much and too too little.

As I said, I consider it rudimentary, which indicates that it's everything
but perfect.


JW
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top