Current location: Hot Scripts Forums » General Web Coding » JavaScript » Help with form validation script


Help with form validation script

Reply
  #1 (permalink)  
Old 11-05-09, 08:33 AM
kevinkhandublin kevinkhandublin is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Help with form validation script

Hi Guys,

Im new to JS and need some help..

I have a contact form on my webpage and i want to put in an alert box if people done enter a field. Below is the html i have for the form

PHP Code:

 <form id="form" method="post" action="consultation.php" onsubmit="return validate(this)">

           <
p>
             <
label>Name:</label>
             <
input type="text" name="name" id="name" />
           </
p>
           <
p>
             <
label>Company:</label>
             <
input type="text" name="company" id="company" />
           </
p>
           <
p>
             <
label>Email:</label>
             <
input type="text" name="email" id="email" />
           </
p>
           <
p>
             <
label>Phone:</label>
             <
input type="text" name="phone" id="phone"/>
           </
p>
          
           <
p style="margin-bottom:0px">
             <
input class="submit_btn" type="image" src="images/submit_btn.gif" name="submit" value="Submit"  />
           </
p>
         </
form
and here is the external Java Script file that iv made so far

PHP Code:




      
var nName nForm['name'];
        var 
nCompany nForm['company'];
        var 
nEmail nForm['email'];
        var 
nPhone nForm['phone'];
        
    if (
nName.value.replace(/\s/g"").length 1)
            {
             
alert('Please enter your full name');
             return 
false;
            }
            
        if (
nCompany.value.replace(/\s/g"").length 1)    
                {
             
alert('Please enter your company name');
             return 
false;
            }
        
            if (!/^\
w+[\w|\.|\-]{0,1}\w*[\w|\.|\-]{0,1}\w*\@\w+[\w|\-]{0,1}\w*[\w|\-]{0,1}\w*\.{1,1}[a-z]{2,4}$/.test(nEmail.value))
            {
             
alert('Please enter your correct email address');
             return 
false;
            }    
    
    if (!/[\
d\s-]+$/.test(nPhone.value) || !/\d{10}/.test(nMobile.value.replace(/[\s-]/g""))) // must contain 10 digits;
            
{
             
alert('Please enter your correct phone number');    
             return 
false;
            } 
iv referenced this Java script file in the head of the html document..

Can anyone help me make this script please...

THanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Space Above Form xavier039 CSS 1 07-13-09 10:52 PM
looking for a php script to clean up form info before sending dreamydesigner Script Requests 9 04-11-08 01:31 PM
CSS Border Width Question. nova912 CSS 6 09-07-06 09:13 AM
Java Script Form Validation blessedrub JavaScript 1 10-15-04 10:03 AM


All times are GMT -5. The time now is 01:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.