Click to See Complete Forum and Search --> : validation
tinernet
09-24-2003, 02:16 PM
im hopless with javascript so anything i try and do i usually end up gettin done for me on here... im tryin to validate theis form, and only allow the sign up to work if the terms and conditions box is checked and all of the fileds are filled in. does anyone kno how u check the email address format, cus its important that its right. the url is http://members.lycos.co.uk/autowar/add.html. i havent uploaded it yet so itl b a min from wen i submit htis.
HELP!
Mike x
Charles
09-24-2003, 02:25 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>
<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
// -->
</script>
<form action="">
<div>
<label>Email Address<input type="text" onchange="if (!this.value.isEmailAddress()) {alert ('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>
You may want to take a look at the code I've written for www.SonoraCabinets.com 's contact page (http://sonoracabinets.com/contact.html).
[J]ona
Looking at how you validate that email address, Jona, it won't really work that well... This will validate:
you@blah...
@.
***@|||.&&&
While this wont:
first.last@your.com
All you're checking is for an @ and a . and that the @ must come before the .
Shut up, I know. :D
Just kiddin'... Thanks for the catch there, I'll get to work on a RegExp...
[J]ona
tinernet
09-24-2003, 02:47 PM
so shall i use charles' email validator then? seen as jona seems to hav been outranked.......
lol just kiddin!
you guys rock thanks a load
The one Charles posted is about as good as they get. I believe Jeff Mott gave you (Jona) the same one in the PHP forums once...
He did, but I need to learn this stuff on my own... Jeff is just too good to fool around with. :p
[J]ona
Charles
09-24-2003, 03:05 PM
Originally posted by pyro
The one Charles posted is about as good as they get. I believe Jeff Mott gave you (Jona) the same one in the PHP forums once... And that's the place from where I stole it.
It's definitely worth the taking... :)
tinernet
09-24-2003, 03:12 PM
for some reason this is buggered, i told u i was crap with js. can ne1 c the prob?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<head>
<title>AutoWar SignUp</title>
<script type="text/javascript">
function validate(frm){
var uname=frm.uname.value;
var pword=frm.pword.value;
var conpword=frm.conpword.value;
var email=frm.email.value;
if(uname==""||uname==" "){
alert("You must enter a UserName.");
frm.uname.focus();
return false;
}
if(pword==""||pword==" "){
alert("You must enter a password.");
frm.pword.focus();
return false;
}
if(conpword==""||conpword==" "){
alert("You must confirm your password.");
frm.pword.focus();
return false;
}
if(!(pword=conpword)){
alert("Your passwords do not match.");
pword=="";
conpword=="";
frm.pword.focus();
return false;
}
if(email==""||email==" "){
alert("You must confirm your password.");
frm.pword.focus();
return false;
}
else {return false;
}
String.prototype.isEmailAddress = function () {
return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)
}
if (!document.register.email.value.isEmailAddress()) {
alert ('Please enter a valid email address e.g. me@me.com.');
document.register.email.value='';
document.register.email.value.focus()
}
}
</script>
</head>
<body>
<div align=center>
<form name="register" onsubmit="return validate(this)">
<b>Terms & Conditions:</b><br>
<textarea rows=10 cols=40 name="tc">
1. I will not attempt to hack another username or gain enrtry to the server.
2. I will not use the game as a way of sending offencive messages with mallicious intent.
3. I will not create more than one account.
4. I agree to having my IP banned from playing the game by the webmaster for a good reason.
5. I will not copy, reproduce or sell this game in any way.
</textarea><br>
<input type=checkbox name="agree">I agree to the AutoWar Terms & Conditions<br><br>
<table border="0">
<tr>
<td>UserName: </td><td><input type=text size=15 name="uname"></td>
</tr><tr>
<td>Password: </td><td><input type=password size=15 name="pword"></td>
</tr><tr>
<td>Confirm Password: </td><td><input type=password size=15 name="conpword"></td>
</tr><tr>
<td>Email Address*: </td><td><input type=text size=20 name="email"></td>
</tr>
</table>
<br><input type="submit" value="SignUp">
<br><br>*Must be correct
</form>
</div>
</body>
</html>
Charles
09-24-2003, 04:47 PM
I've takes the liberty to correct you HTML as well.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0eml; text-align:right}
input {margin:0em 1ex}
fieldset {padding:1em}
legend {font-weight:bold}
-->
</style>
<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
function validate(f) {
if (!/\S/.test(f.uname.value)) {alert ('You must enter a User Name.'); f.uname.focus(); return false};
if (!/\S/.test(f.pword.value)) {alert ('You must enter a Password.'); f.pword.focus(); return false};
if (!/\S/.test(f.conpword.value)) {alert ('You must confirm your password.'); f.conpword.focus(); return false};
if (f.conpword.value != f.pword.value) {alert ('Your passwords need to match.'); f.conpword.focus(); return false};
if (!/\S/.test(f.email.value)) {alert ('You must enter a valid email address.'); f.email.focus(); return false};
}
// -->
</script>
<form action="" onsubmit="return validate(this)">
<div style="width:25em">
<fieldset>
<legend>Terms & Conditions</legend>
<textarea rows="10" cols="40">
1. I will not attempt to hack another username or gain enrtry to the server.
2. I will not use the game as a way of sending offencive messages with mallicious intent.
3. I will not create more than one account.
4. I agree to having my IP banned from playing the game by the webmaster for a good reason.
5. I will not copy, reproduce or sell this game in any way.
</textarea>
<label><input type=checkbox name="agree">I agree to the AutoWar Terms & Conditions<label>
</fieldset>
<fieldset>
<legend>Regester</legend>
<label>User Name<input type="text" size="20" name="uname"></label>
<label>Password<input type="password" size="20" name="pword"></label>
<label>Confirm Password<input type="password" size="20" name="conpword"></label>
<label>Email Address<input type="text" name="email" onchange="if (!this.value.isEmailAddress()) {alert ('That would not appear to be a valid email address.'); this.value=''; this.focus()}"></label>
</fieldset>
<div style="text-align:center">
<button type="submit">Sign Up</button>
</div>
</form>
herodote92
06-07-2005, 01:53 PM
I tested Charles' function. It accepts things like me!yesme@something.com, which my Outlook Express blandly refuses.
???
...which my Outlook Express blandly refuses.Which just tells us the Outlook Express can't handle a perfectly good email address, according to RFC 2822 (http://www.faqs.org/rfcs/rfc2822.html)...