By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

help modifying script to validate text field

P: n/a
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[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].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[i]))!=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[i])&&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[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].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.toLower Case();">
<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>
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Mike" <ms*****@photoshelf.net> schreef in bericht
news:5e*************************@posting.google.co m...

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:


I did a first-aid rewrite of the scripts, check:

http://www.jwscripts.com/playground/check_email.php

Still needs work, but I think that you will be able to pick it up from here.
JW

Jul 20 '05 #2

P: n/a
"Janwillem Borleffs" <jw@jwscripts.com> wrote in message news:<3f*********************@news.wanadoo.nl>...
"Mike" <ms*****@photoshelf.net> schreef in bericht
news:5e*************************@posting.google.co m...

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:


I did a first-aid rewrite of the scripts, check:

http://www.jwscripts.com/playground/check_email.php

Still needs work, but I think that you will be able to pick it up from here.
JW


Sorry JW, I don't know how to continue, I'm just a beginner. Any more
help is appreciated.
Mike
Jul 20 '05 #3

P: n/a

"Mike" <ms*****@photoshelf.net> schreef in bericht
news:5e**************************@posting.google.c om...

Sorry JW, I don't know how to continue, I'm just a beginner. Any more
help is appreciated.


It's more or less useful now, again see:
http://www.jwscripts.com/playground/check_email.php

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.
JW


Jul 20 '05 #4

P: n/a
"Janwillem Borleffs" <jw@jwscripts.com> writes:
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., fo*****@example.com or
"Mr. Foo Bar"@example.com (both of which are perfectly good e-mail
adresses).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a

"Lasse Reichstein Nielsen" <lr*@hotpop.com> schreef in bericht
news:k7**********@hotpop.com...

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

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.