Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > Javascript

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 09-01-2014, 02:16 AM   #1
johnstyle
Registered User
 
Join Date: Dec 2013
Posts: 327
data validation

How to do data validation while submitting form?
johnstyle is offline   Reply With Quote

Old 09-03-2014, 12:18 AM   #2
george.web13
Registered User
 
Join Date: Jul 2014
Location: Athens, Greece
Posts: 461
You validate your data with javascript, before sending them to the server.
Example:

<form id="contact_form" method="post" enctype="multipart/form-data" action="contact.php" >
<input type="text" value="" name="name" id="name" />
<input type="text" value="" name="email" id="email" />
<input type="text" value="" name="phone" id="phone" />
<textarea name="comments" id="comments"></textarea>
<input type="button" class="submit_button" value="SUBMIT" onclick="return validate_contact();" />
</form>

And in javascript:

function validate_contact(){
var name=jQuery.trim($('#name').val());
var email=jQuery.trim($('#email').val());
var comments=jQuery.trim($('#comments').val());

if (name=='' || name.length<3)
{alert ('Please enter your name');return false;}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)==false)
{alert('Please enter valid email address');return false;}
if (comments.length<1)
{alert('Please enter your comments');return false;}

}
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
george.web13 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Entry Outsourcing Services shrikant.softwi Post your ad here 3 10-10-2018 11:57 PM
How to Find Remunerative Data Entry Jobs menchester03 Making money on the web 3 12-28-2014 01:57 PM
Google Analytics vs Webmaster Tools Data James12smith Search Engine Optimization 0 01-13-2014 10:14 PM
Requires Data Entry operator ! rmonline11 General Discussion 2 05-08-2012 09:54 AM


All times are GMT -7. The time now is 10:48 PM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.