Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 11th, 2010, 02:49 AM
Registered User
 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript Validation not working in IE8

Hi, I am working on a website and the validation for the form fields are not workin in ie. Below is the code for validation.

Website address is thealexandraclinic.com.au

Code:
//---------------------------------Phone Validation----------------------------//

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function trim(s)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not a whitespace, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (c != " ") returnString += c;
}
return returnString;
}
function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


//---------------------------------Phone Validation Ends-----------------------//
// JavaScript Document

function querySt(ji) {
 hu = window.location.search.substring(1);
 gy = hu.split("&");
 for (i=0;i<gy.length;i++) {
  ft = gy[i].split("=");
   if (ft[0] == ji) {
   return ft[1];
   }
  }
}

function echeck(str) {

 var at="@"
 var dot="."
 var lat=str.indexOf(at)
 var lstr=str.length
 var ldot=str.indexOf(dot)


 for(i=0;i<lstr;++i)
 {
 if ((str.charAt(i)=='.') && (str.charAt(i+1)=='.'))
 {
 alert("Invalid E-mail ID")
 return false
 }
 if ((str.charAt(i)=='@') && (str.charAt(i+1)=='@'))
 {
 alert("Invalid E-mail ID")
 return false
 }
 }


 if (str.indexOf(".")==0)
 {
 alert("Invalid E-mail ID")
 return false
 }
 if (str.indexOf("@")==0)
 {
 alert("Invalid E-mail ID")
 return false
 }
 if ((str.charAt(lstr-1))=='.')
 {
 alert("Invalid E-mail ID")
 return false
 }
 if ((str.charAt(lstr-1))=='@')
 {
 alert("Invalid E-mail ID")
 return false
 }


 if (str.indexOf(at)==-1){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(dot,(lat+2))==-1){
 alert("Invalid E-mail ID")
 return false
 }

 if (str.indexOf(" ")!=-1){
 alert("Invalid E-mail ID")
 return false
 }
  return true
}

function validate(){
	
 if(document.getElementById('name').value == "") 
 {
  alert("Enter Name");
  document.getElementById('name').focus();
  return false;
 }

if(document.getElementById('name').value == "Name") 
 {
  alert("Enter Name");
  document.getElementById('name').focus();
  return false;
 }

  if(document.getElementById('email').value == "")
 {
  alert("Enter Email");
  document.getElementById('email').focus();
  return false;
 }
 
  if(document.getElementById('email').value == "Email")
 {
  alert("Enter Email");
  document.getElementById('email').focus();
  return false;
 }

 if(document.getElementById('email').value != "")
 {
 if(echeck(document.getElementById('email').value)==false){
  //alert("Enter a valid Email Id");
  document.getElementById('email').focus();
  return false;
  }
 }

var Phone=document.getElementById('phone');

if ((Phone.value==null)||(Phone.value=="")){
alert("Please Enter your Phone Number")
Phone.focus()
return false
}
if (checkInternationalPhone(Phone.value)==false){
alert("Please Enter a Valid Phone Number")
Phone.value=""
Phone.focus()
return false
}

if(document.getElementById('phone').value == "Telephone")
{
alert("Enter Phone");
document.getElementById('phone').focus();
return false;
}
 
 
 
 
 
 
 if(document.getElementById('add').value == "") 
 {
  alert("Enter Address");
  document.getElementById('add').focus();
  return false;
 }

if(document.getElementById('add').value == "Address") 
 {
  alert("Enter Address");
  document.getElementById('add').focus();
  return false;
 }
 if(document.getElementById('query').value == "") 
 {
  alert("Enter Your Query");
  document.getElementById('query').focus();
  return false;
 }

if(document.getElementById('query').value == "Your Query") 
 {
  alert("Enter Your Query");
  document.getElementById('query').focus();
  return false;
 }
  var select = document.getElementById('attn');
 if(document.getElementById('attn').options[select.selectedIndex].value == "How did you hear about us?")
 {
  alert("Please select a valid option 'How did you find us?'");
  document.getElementById('attn').focus();
  return false;
 }
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript validation not working in content page Manoj Bisht ASP.NET 2.0 Basics 0 March 3rd, 2008 02:21 AM
javascript datetime validation Hannibal Javascript 1 December 5th, 2007 06:39 AM
Form Validation not exactly working as intended.. Smythe Classic ASP Basics 1 July 25th, 2006 04:56 PM
Validation not working Ajay Jain General .NET 1 February 26th, 2004 03:07 AM



All times are GMT -4. The time now is 05:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.