java script validation

java script validation

View Answers

March 30, 2009 at 11:21 AM

Hi friend,

Code to create a jsp page "contact.jsp" with javascript validation :

<HTML>
<HEAD>
<TITLE>Contact Details</TITLE>
<style>
.txt {
font-size:12px;
font-family: Arial;
}
.txthead {
font-size:12px;
font-family: Arial;
font-weight:bold;
}
.mainhead{
font-size:14px;
font-family: Arial;
font-weight:bold;
}
.mandatory
{
color:#ff0000;
}
</style>
<script>

// 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;
}

var testresults
function checkemail(){
var str=document.screenForm.email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{

testresults=false
}
return (testresults)
}

March 30, 2009 at 11:22 AM

function validate()
{

var Phone=document.screenForm.phone.value;
if(document.screenForm.name.value=="")
{

alert("Please enter name.");
return false;

}
if(document.screenForm.company_name.value=="")
{
alert("Please enter company name.");
document.screenForm.company_name.focus();
return false;

}
if(document.screenForm.email.value=="")
{
alert("Please enter email.");
document.screenForm.email.focus();
return false;

}
if(document.screenForm.email.value!="")
{
if(!checkemail())
{
alert("Please input a valid email address!");
document.screenForm.email.focus();
return false;
}

}

if(document.screenForm.phone.value=="")
{
alert("Please enter phone.");
document.screenForm.phone.focus();
return false;

}

if(document.screenForm.street.value=="")
{
alert("Please enter street.");
document.screenForm.street.focus();
return false;

}
if(document.screenForm.city.value=="")
{
alert("Please enter city.");
document.screenForm.city.focus();
return false;

}
if(document.screenForm.postcode.value=="")
{
alert("Please enter postcode.");
document.screenForm.postcode.focus();
return false;

}
return true;

}
</script>

</HEAD>

<BODY>

March 30, 2009 at 11:22 AM

<br><br>
<form name="screenForm" action="success.html" method="post" onsubmit="return validate();">
<table style="background-color:#efefef;" align="center">

<tr><td colspan=2> &nbsp;</td></tr>
<tr style="background-color:#CAC5C5;"><td colspan=2 class="txthead"> Contact Details</td></tr>
<tr>
<td class="txt">Name<span class="mandatory">*</span></td>
<td ><input type="text" name="name" id="name" size="35"></td>
</tr>
<tr>
<td class="txt">Company Name<span class="mandatory">*</td>
<td ><input type="text" name="company_name" id="company_name" size="35"></td>
</tr>

<tr>
<td class="txt">Email Address<span class="mandatory">*</td>
<td ><input type="text" name="email" id="email" size="40"></td>
</tr>
<tr>
<td class="txt">Phone Number<span class="mandatory">*</td>
<td ><input type="text" name="phone" id="phone" ></td>
</tr>
<tr>
<td class="txt">Street<span class="mandatory">*</td>
<td ><input type="text" name="street" id="street" size="35"></td>
</tr>
<tr>
<td class="txt">City<span class="mandatory">*</td>
<td ><input type="text" name="city" id="city" size="35"></td>
</tr>
<tr>
<td class="txt">Postcode<span class="mandatory">*</td>
<td ><input type="text" name="postcode" id="postcode" ></td>
</tr>
<tr>
<td class="txt" colspan=2><span class="mandatory">* Indicates mandatory</td>

</tr>
<tr>

<td colspan=2 align="center"><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
</form>
</table>
</BODY>
</HTML>


Thanks

March 30, 2009 at 3:21 PM

Hey buddy


Dont you feel that is huge try this
http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
go to that site and download the js page and use it as directed its much simpler once u understand that javascript code

Cheers









Related Tutorials/Questions & Answers:
validation in java script
validation in java script  i have put this code for only entering integer value in text box however error occured.. if(document.formname.textbox1.value!=="") { var rn,i; rn=document.formname.textbox1.value; for(i=0i='0' &
java script validation - Java Beginners
java script validation  hi, i have two radio buttons yea and no. all text fiels r deactivated, when i click no radio button. its get active... Button Validation function callEvent1
Advertisements
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
stuts java script validation is not working.
stuts java script validation is not working.  --of jsp page-- Enter name: Enter pass: <html:submit/> --of validation.xml-- <form name="logonForm"> <
stuts java script validation is not working.
stuts java script validation is not working.  hello my stuts client side validation is not working. pls help me out i have put jsp file's code and validation.xml file's code. pls help --of jsp page-- > <html:form action
java script validation - Java Beginners
java script validation  how to do validations in j s p thru java script  Hi friend, Code to create a jsp page "contact.jsp" with javascript validation : Contact Details .txt { font-size:12px; font
please send me java script for html validation - Java Beginners
please send me java script for html validation  please send me code for javascript validation .........please send me its urgent a.first:link { color: green;text-decoration:none; } a.first:visited{color:green;text
Form Validation With Java Script
Form Validation With Java Script   ... the Validation in  JavaScript and  your Validation in JavaScript program. JavaScript  Java script is used to validate forms, that means checking the proper
Java Script
Java Script  Hello Sir, Is it possible to select only current date from datetimepicker in struts2 through java script validation. Means when i select.... Try to send me java script validation code for this purpose that user won't
Java script
Java script  Source code for capturing the screen using Java Script
Java Script
Java Script  why we are using java script
Java Script
Java Script  Hi, Any one please share a code to swap the 2strings using java script
Java Script
Java Script  What is Java Script? How to learn Java Script?   Hi Java Script is client side programming language. It runs on browser.... You can learn Java Script from our JavaScript - JavaScript Tutorial pages
java script
java script  how to write a Java script program to enter number in two text fields and then automatically display the total in another text field
Java script
Java script  a java script code for accept 10 numbers from the user and print in the descending order without using sort method
java script
java script  Hi, Any one please tell me how, to store below elements in an array using java script 12,13,14,a,b,xyz
Java Script.
Java Script.  Hi Sir, The below java script code is not working in Google chrome can yo give me the solution as soon as possible. <script type="text/javascript"> function setValue(){ var val=""; var frm
Java Script.
Java Script.  Hi Sir, The below java script code is not working in Google chrome can yo give me the solution as soon as possible. <script type="text/javascript"> function setValue(){ var val=""; var frm
Java Script.
Java Script.  Hi Sir, The below java script code is not working in Google chrome can yo give me the solution as soon as possible. <script type="text/javascript"> function setValue(){ var val=""; var frm
Java Script.
Java Script.  Hi Sir, The below java script code is not working in Google chrome can yo give me the solution as soon as possible. <script type="text/javascript"> function setValue(){ var val=""; var frm
Java Script.
Java Script.  The below code is nit working in Google chrome can any one tell me the solution as soon as possible. <script type="text/javascript"> <!-- function setValue(){ var val=""; var frm
Java Script.
Java Script.  Hi i want to submit two form using javascript.The below code submitting two forms in server but its not working in browser like chrome and firefox am struggling for many days give me solution as soon as possible
Java Script
Java Script  I want to display an error message for the validation of email at the top of the page in red font i want to use java scripts but i dont want to use alert box what i need to do   <html> <script>
java script
java script  how will you identify whether the number entered by the user has two digits or three digits.Assuming that the user enters only a three digit or two digit number.   <HTML> <HEAD> <SCRIPT
java script
java script  write a java script code which provide a menu for user which will enable him/her to either add or subtract or multiply or divide two numbers and produce the corresponding result.   <html> <
java script
java script  when you click a button how will you change the background color of a web page
java script
java script  I want to display set of radio buttons after i select one option of the combobox
java script
java script  what is the use of getElementById() method in jsp. and give me its full knowledge with a example
java script
java script  hi deepak, i have small doubt in the date ranges that when i select the date range then it display on the text boxes. example:suppose i select the weekly date range then the dates are display on the text boxes up
How to use email validation check through java script in jsp page
How to use email validation check through java script in jsp page...; This is detailed java code that explains how to use java script validator in jsp page...;Javascript"> /* This is code to check valid email using java script. */ function
Java Script location.replace method
Java Script location.replace method  Hi, What does `Print `{<SCRIPT LANGUAGE="JavaScript"> location.replace("} & urlpop & {","BOTTOM") </SCRIPT>} this mean as this is written in an Lotus Script agent and I
defining numbers in Java Script
defining numbers in Java Script  Explain about defining numbers in Java Script
Java script in servlet
Java script in servlet  Hi. How to use javascript inside java servlet? Thanks in advance
Sitemap Java Script Tutorial
in JavaScript | Email validation is JSP using JavaScript | Java Script...) In JavaScript | Conditions In Java Script | Looping in JavaScript | Functions... Application With Ant and Deploying on Jboss 3.0 | J2EE Tutorial - Java Bean
form to java script conversion
form to java script conversion  I am using a form one more form cotain a piece of code . how to convert it to java script to function it properly..." name="ie" value="UTF-8" /> <input type="text" name="q" size="55" />
java script - Development process
java script  how could i devlop code for create widget. i need to generate java script that if paste to any other web site will generate the widget. a widget can contain image text video or combination
qunit jquery with java script
qunit jquery with java script  hi deepak How to write a javascript code and do the test by using qunit sample application and as I am new to testing how to setup the environment for java script testing? where should I run
java script - Ajax
java script  i know basic of java script. i want to gain more knowledge in java script. please send a link or guidelines to me. and ajax also my mail address is [email protected]  Hi friend, Javascript
script error - Java Beginners
script error  hi, Is it possiple to use PHP function under the script tag. plz help me. thank u in advance. regards, sakthi  Hi Friend, Yes It is possible to use PHP function under the script Tag. Thanks
java script - Ajax
java script  I have a java script function and getting "pitems" list values in select, and i want to send the values in the form of List to my CommonService class. Below code is not working... function f_getPop
Java script - Development process
Java script  Dear Sir/Mdm I have a probem, when any user close the browser without logout at that moment the user should be logout, I wrote some java script code for that its working in IE not Fire Fox, actually
java script - Development process
java script  hi.. how to get previous and next buttons inside the table in the same page as like our mails in the inbox.  Hi Friend, Try the following code: ID Name Address Contact
Java Script Help
Java Script Help  I have written a countdown timer using javascript... help --- <html> <head> </head> <script language....' window.location = 'crdtd.php?q=b
script problem - Java Beginners
script problem  Even though both .js file and .jsp file present in the same location,script is not working in mozilla but working in Internet... what i have written present in same location. but the script
java script - Struts
java script  how validation for date is performed in the top-down select.if the user clicks submit without selecting the date, month and year. what is the validation for selecting a date that is in future like jul 2009
java script - Ajax
java script  I have a java script function and getting "pitems" list values in select, and i want to send the values in the form of List to my CommonService class. I want to display the selected value from the select box
java script - JSP-Servlet
java script  what is the use of hidden fields in java script? if a page has 3 links the first link should be enabled and others should be disabled. once the form inside the first link is filled and submitted the next link should
java script and velidatores - Security
java script and velidatores  i made a job portal and in it many fields which required validate how i do throw java script.. can you help me please send me common validate function which used in any site.....   Hi
script code - Java Beginners
script code  hi, thanks for ur fast reply. plzz, give me a sample code for PHP function under script tag. regards, sakthi  Hi friend, Code to help in solving the problem : Hello PHP World

Ads