Home Answers Viewqa Java-Beginners java script validation

 
 


asha
java script validation
4 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners

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 Pages:
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
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
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  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>
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
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
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
Validation
Validation  Hi.. How to Validate blank textfield in java that can accepts only integers?   Have a look at the following link: http://www.roseindia.net/tutorial/java/swing/howtovalidatetextfield.html
Validation
Validation  I am developing a standalone application which requires me to save the email id and contact number (mobile number) in a database (MySQL). How do i perform a check using JAVA on the data before storing
validation
language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding
Sitemap Java Script Tutorial
| Email validation is JSP using JavaScript | Java Script Code of Calendar... | Conditions In Java Script | Looping in JavaScript | Functions in JavaScript... Application With Ant and Deploying on Jboss 3.0 | J2EE Tutorial - Java Bean
password validation with special character
password validation with special character  how to validate password with special character using java script
Time validation
box is in the correct format or not using java script. Please help me for doing...;html> <script language="JavaScript"> function check(timeStr) { var
struts validation
struts validation  I want to apply validation on my program.But i am failure to do that.I have followed all the rules for validation still I am..... CreateGroup.jsp <%@ page language="java" pageEncoding="ISO-8859-1"%> <
struts validation
struts validation  I want to apply validation on my program.But i am failure to do that.I have followed all the rules for validation still I am..... CreateGroup.jsp <%@ page language="java" pageEncoding="ISO-8859-1"%> <
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
Java script  Source code for capturing the screen using Java Script
Java Script
Java Script  why we are using java script
validation - JSP-Servlet
thankful to u.......  Hi Friend, In a very simple way when you use java-script kind of validations which are done before submission of forms are client side validation and when you submit the form it passes the data to some file over
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
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... valid email using java script. */ function emailCheck(str) { var
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
Validation code - Java Interview Questions
************* Java Script Calender Date Picker function isNumberKey(value... **************** Java Script Calender Date Picker function isNumberKey...Validation code  Hi, Anyone can please send me a javascript function
address1 and address 2 validation
address1 and address 2 validation  Hi sir/Madam, I m doing One Project Quite now. I would like to validate address that comprises of door numbers,street name, area name .Please provide java-script to do the same.Thanks in advance
Radio button Validation
; Javascript radiobutton validation: <html> <script language...Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please
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
problem in java script - Java Server Faces Questions
problem in java script  hi deepak i want to apply validation..."); } } email   Hi, Email validation in JavaScript... validation User Name
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
validation - Development process
validation  hi.. how to validate the username,email,mobilenumber,radio button,drop down list using the java script.   Hi Friend, Try the following code: 1)form.html: Enter Username Enter Email ID
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
Client Side validation in Struts 2 application
that will generate Java Script code for client side validation. In the last section we... for generating the client side java script.   Developing JSP pages Here...; Click on the "Login" button without entering anything. Java Script
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
defining numbers in Java Script
defining numbers in Java Script  Explain about defining numbers in Java Script

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.