Forums
This topic is locked
Form validation issues with firefox
Posted 17 Feb 2006 18:04:09
1
has voted
17 Feb 2006 18:04:09 David Tregoning posted:
The following code works in both IE and Firefox<font color=red><pre id=code><font face=courier size=2 id=code>
function DB_Validate(){
var errMessage = '';
var t = document.getElementById('frmTitle');
var n = document.getElementById('frmFirstName');
var sn = document.getElementById('frmSurName');
var a = document.getElementById('frmAddress');
var tn = document.getElementById('frmTown');
var c = document.getElementById('frmCounty');
var pc = document.getElementById('frmPostcode').value;
var e = document.getElementById('frmEmail').value;
var p = document.getElementById('frmPhone').value;
var PostCodeFilter = /^\D\w{1,3}\s*\w{2,4}$/
var PhoneFilter = /^\d{10,}$/
if(t.options.selectedIndex == 0) errMessage += 'Please Select Your Title.\n';
if(n.value == '') errMessage += 'You must enter your First Name.\n';
if(sn.value == '') errMessage += 'You must enter your Surname.\n';
if(a.value == '') errMessage += 'You must enter your Address.\n';
if(tn.value == '') errMessage += 'You must enter your Town.\n';
if(c.value == '') errMessage += 'You must enter your County.\n';
if (!PostCodeFilter.test(pc)) errMessage += 'You must enter a valid Post Code.\n';
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z]{2,9})$/; // valid
if ((reg1.test(e)) || (!reg2.test(e))) errMessage += 'You must enter a valid e-mail address.\n';
if (!PhoneFilter.test(p)) errMessage += 'You must enter a valid Contact Phone Number.\n';
if(errMessage != ''){
alert('The information you have submitted is incomplete.\n\n' + errMessage + '\nPlease correct the errors above and re-submit the form.');
return false;
}else{
return true;
}
}
</font id=code></pre id=code></font id=red>
However the following code which is an expanded very of the above only works in IE
<pre id=code><font face=courier size=2 id=code>
function DB_Validate(){
var errMessage = '';
var t = document.getElementById('frmTitle');
var n = document.getElementById('frmFirstName');
var sn = document.getElementById('frmSurName');
var e = document.getElementById('frmEmail').value;
var p = document.getElementById('frmPhone').value;
var s = document.getElementById('frmSource');
var so = document.getElementById('frmSourceOther');
var a = document.getElementById('frmAddress');
var tn = document.getElementById('frmTown');
var c = document.getElementById('frmCounty');
var pc = document.getElementById('frmPostcode').value;
var cn = document.getElementById('frmCompanyName').value;
var ro = document.getElementById('frmRegOfficeFacility');
var filter = /^[\w\.\-]+@[a-z][\w\-\.]+\.(\w{2}\.\w{2,3})|^[\w\.\-]+@[a-z][\w\-\.]+\.(\w{3,4})$/
var PostCodeFilter = /^\D\w{1,3}\s*\w{2,4}$/
var PhoneFilter = /^\d{10,}$/
if(t.options.selectedIndex == 0) errMessage += 'Please Select Your Title.\n';
if(n.value == '') errMessage += 'You must enter your First Name.\n';
if(sn.value == '') errMessage += 'You must enter your Surname.\n';
var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
var reg2 = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z]{2,9})$/; // valid
if ((reg1.test(e)) || (!reg2.test(e))) errMessage += 'You must enter a valid e-mail address.\n';
if (!PhoneFilter.test(p)) errMessage += 'You must enter a valid Contact Phone Number.\n';
if(s.options.selectedIndex == 0 && so.value == '') errMessage += 'Please tell us where you heard about us.\n';
if(pa == '') errMessage += 'Please Select a Formation Package.\n';
if(cn == '') errMessage += 'You must enter a Company Name to be Registered.\n';
if(ro.checked != true){
if(a.value == ''){
(pa == 'N')?errMessage += 'You must tell us your Address.\n':errMessage += 'You must tell us your Registered Office Address.\n';
}
if(tn.value == ''){
(pa == 'N')?errMessage += 'You must tell us your Town.\n':errMessage += 'You must tell us your Registered Office Town.\n';
}
if(c.options.selectedIndex == 0){
(pa == 'N')?errMessage += 'Please Select Your County.\n':errMessage += 'Please Select Your Registered Office County.\n';
}
if(!PostCodeFilter.test(pc))errMessage += 'You must enter a valid Postcode.\n';
}
if(errMessage != ''){
alert('The information you have submitted is incomplete.\n\n' + errMessage + '\nPlease correct the errors above and re-submit the form.');
return false;
}else{
return MW_CheckName();
}
}
</font id=code></pre id=code>
Not knowing much about javascript does anybody know what is being used in the second piece of code that firefox is ignoring.
Thanks in advance