Email, Password og brugernavns validering
Jeg har problemer med at få dette validerings script til at virker<script>
function Validate(form){
var UserName = form.Username.value;
var Email1 = form.email1.value;
var Email2 = form.email2.value;
var Pass1 = form.pass1.value;
var Pass2 = form.pass2.value;
var alertmsg;
alertmsg = validatePass(Pass1,Pass2);
//alertmsg = alertmsg + validateEmail(Email1,Email2);
alertmsg = alertmsg + validateName(UserName);
alert(alertmsg);
return false;
}
function validatePass(Pass1,Pass2){
var AlertMSG;
AlertMSG = '';
if (Pass1 != Pass2){
AlertMSG = AlertMSG + '- The retyped password must be identical with the first\n';
}
if (Pass1.length < 5){
AlertMSG = AlertMSG + '- Your password needs to be at least 5 charecters!\n';
}
return AlertMSG;
}
function validateName(Username){
var AlertMSG = '';
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++)
{
if (addr.indexOf(invalidChars.charAt(i),0) > -1)
{
AlertMSG = AlertMSG + 'Username contains one of the invalid characters\n ( \/\'\\ ";:?!()[]\{\}^| )\n';
}
}
return AlertMSG;
}
function validateEmail(addr)
{
var AlertMSG = '';
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
if (addr.indexOf(invalidChars.charAt(i),0) > -1)
{
AlertMSG = AlertMSG + 'email address contains invalid characters\n';
}
}
for (i=0; i<addr.length; i++){
if (addr.charCodeAt(i)>127){
AlertMSG = AlertMSG + 'email address contains non ascii characters.\n';
}
}
var atPos = addr.indexOf('@',0);
if (atPos == -1) {
AlertMSG = AlertMSG + 'email address must contain an @\n';
}
if (atPos == 0) {
AlertMSG = AlertMSG + 'email address must not start with @\n';
}
if (addr.indexOf('@', atPos + 1) > - 1) {
AlertMSG = AlertMSG + 'email address must contain only one @\n';
}
if (addr.indexOf('.', atPos) == -1) {
AlertMSG = AlertMSG + 'email address must contain a period in the domain name\n';
}
if (addr.indexOf('@.',0) != -1) {
AlertMSG = AlertMSG + 'period must not immediately follow @ in email address\n';
}
if (addr.indexOf('.@',0) != -1){
AlertMSG = AlertMSG + 'period must not immediately precede @ in email address\n';
}
if (addr.indexOf('..',0) != -1) {
AlertMSG = AlertMSG + 'two periods must not be adjacent in email address\n';
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
AlertMSG = AlertMSG + 'invalid primary domain in email address\n';
}
return AlertMSG;
}
</script>
<form name="RegForm" method="post" action="?" enctype="multipart/form-data" onsubmit="return Validate(this)"
class="RegForm">
<table ID="Table1">
<tr class="RegNeeded">
<td>Username:</td>
<td><input type="text" name="Username" ID="Text1"></td>
<td></td>
</tr>
<tr class="RegNeeded">
<td>Password:</td>
<td><input type="password" name="pass1" ID="Password1"></td>
<td></td>
</tr>
<tr class="RegNeeded">
<td>Retype Password:</td>
<td><input type="password" name="pass2" ID="Password2"></td>
<td></td>
</tr>
<tr class="RegNeeded">
<td>Email:</td>
<td><input type="text" name="email1" ID="Text2"></td>
<td></td>
</tr>
<tr class="RegNeeded">
<td>Retype Email:</td>
<td><input type="text" name="email2" ID="Text3"></td>
<td></td>
</tr>
<TR class="RegAddress">
<TD>Address</TD>
<TD><input type="text" name="address" ID="Text4"></TD>
<TD></TD>
</TR>
<TR class="RegAddress">
<TD>Zip code</TD>
<TD><input type="text" name=">zip" ID="Text5"></TD>
<TD></TD>
</TR>
<TR class="RegAddress">
<TD>Country</TD>
<TD><select name="Country">
<option value="0" selected>Select a country</option>
<option>-----------</option>
<%
set RegCountryDic = GetAllCountries()
for each RegCountry in RegCountryDic.Items
Response.Write "<option value=""" & RegCountry.CountryID & """>" & RegCountry.Name & "</option>" & vbCRLF
next
%>
</select></TD>
<TD></TD>
</TR>
<TR class="RegExtra">
<TD>My Picture</TD>
<TD><input type="file" name="FILE1" ID="File1"></TD>
<td></td>
</TR>
<TR class="RegExtra">
<TD valign="top">My story /<br>
description</TD>
<TD><textarea cols="25" rows="4" name="Description"></textarea></TD>
<TD></TD>
</TR>
<tr class="RegType">
<td>I want to Buy</td>
<td><input type="checkbox" name="Buy" value="1"></td>
<td></td>
</tr>
<tr class="RegType">
<td>I want to Sell</td>
<td><input type="checkbox" name="Sell" value="1"></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="Submit" value="Register" ID="Submit1"></td>
</tr>
</table>
</form>
