Ragini Shukla
js
4 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners

View Answers

October 16, 2008 at 12:32 PM


hai frnd........


<script language="JavaScript1.2">
function checknumber(){
var cont=document.form.txtNAMEOFCONT.value
var conlabeng=document.form.txtNAMEOFCONLABENG.value
var anum=/(^\d+$)|(^\d+\.\d+$)/

testresult=true

if(cont=="")
{
alert("Please type your cont!")
testresult=false
}

if(conlabeng=="")
{
alert("Please type your conlabeng!")
testresult=false
}

return (testresult)
}

</script>
<script>
function checkban(){
if (document.layers||document.all||document.getElementById)
return checknumber()
else
return true
}
</script>

change the form tag to <form name="form" onSubmit="return checkban()" action="your page" method="post">



this is the javascript to check the text box is null.......

thanks and regards
prashu
prashobvee@gmail.com


October 16, 2008 at 1:02 PM


Hi Ragini,

<html>
<title>character validation in jsp</title>
<head>

<script type="text/javascript">

var digits = "0123456789";

var phoneNumberDelimiters = "()- ";

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

function isProper(string) {

if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}

October 16, 2008 at 1:03 PM


function validateForm(theForm){


if(theForm.username.value==""){
//Please enter username
alert("Enter the First Name.");
theForm.username.focus();
return false;
}

if (isProper(theForm.username.value) == false) {
alert("Please enter a valid First Name.");
theForm.username.focus();
return false;
}

if(theForm.username.value.length > 20) {
alert("Maximum 20 characters allowed for 'First Name'.")
theForm.username.focus() ;
return false;
}


if(theForm.address.value==""){
//Please enter address
alert("Enter the Address.");
theForm.address.focus();
return false;
}

if (isProper(theForm.address.value) == false) {
alert("Please enter a valid address.");
theForm.address.focus();
return false;
}

if(theForm.address.value.length > 50) {
alert("Maximum 50 characters allowed for 'address'.")
theForm.address.focus() ;
return false;
}

var Phone=document.frmSample.txtPhone;

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

return true;
}
</script>
</head>

October 16, 2008 at 1:03 PM


<body>
<br><br><br><br>
<center>
<table border="1" width="50%" bgcolor="lightpink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<form name="frmSample" method="POST" action="" onsubmit="return validateForm(this);">

<h2 align="center">Validation Form</h2>
<table border="1" width="100%" cellspacing="0" cellpadding="0">

<tr>
<td width="50%"><b>User Name:</b></td>
<td width="50%"><input type="text" name="username" size="20"/> </td>
</tr>
<tr>
<td width="50%"><b>Address:</b></td>
<td width="50%"><input type="text" name="address" size="50"/> </td>
</tr>
<tr>
<td width="50%"><b>Phone Number:</b></td>
<td width="50%"><input type="text" name="txtPhone" size="20"/> </td>
</tr>

</table>
<p><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset"></p>

</form>
</td>
</tr>
</table>
</center>
</body>
</html>
------------------------------------------------

Visit for more information.

http://www.roseindia.net/jsp/

Thanks.









Related Pages:
EXT JS
EXT JS   i want to create a grid in extjs to display data from mysql and if i want to edit the data i must update through extjs only and must update in mysql database. please help me with sample code. thank you
Lightbox JS
Lightbox JS/font>       Lightbox JS is a simple, unobtrusive script used to overlay images on the current page. It`s a snap to setup and works on all modern browsers. Read full
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
js,,mysql - JSP-Servlet
js,,mysql  Hi, I want a jsp code for editing,deleting data retrieved from from the mysql database and displayed in a html page .Can anybody provide me a code for including edit and delete options with the following code
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello all, I am working on JSP-servlets n MVC.I am facing a problem. on the web..."; response.setContentType("text/plain"); response.getWriter().write(url); in js function
Ext Js form example.
; In this simplified application and easy to learn Ext Js Tutorial I will show you how to develop a form in Ext Js framework. The Ext Js form will take...; framework in shortest possible time. Ext JS provides UI elements for developing web
Create a input button inside js function
Create a input button inside js function  I call my js function from HTML code from another file. Now I would like to create a input button on page... is the right way   I call my js function from HTML code from another file
How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js?
) by calling the function from js?  How to change the value of a variable which is set in jsp (by jstl method) by calling the function from js? I set... is written in js. Is there any solution
Ext
Ext       Ext Js  form example In this simplified application and easy to learn Ext Js Tutorial I will show you how to develop a form in Ext Js framework. The Ext Js form
JS-Sorcerer: JavaScript Development Tool
JS-Sorcerer: JavaScript Development Tool       JavaScript Reporter finds problems in JavaScript files in a single step, letting you spend more time improving your website
Downloading and Installing jQuery
for developing our demo application. jQuery comes as single js file. So, its very easy...://jquery.com/ and download jquery-1.2.6.min.js and add into js directory
Ofbiz framework - Java Beginners
Ofbiz framework  Hi All, Im new to Ofbiz framework.Can anyone please tell me how to pass a particular div id in a ftl to a js through the js call in that particualr ftl
PHP/HTML/AJAX Question
PHP/HTML/AJAX Question  I have a PHP/HTML program that sends a parm to a .JS program using Ajax logic (onchange) and it returns it. It returns... should the code to do it be (in the .js or as a html or PHP statement
how to access javascript in mozilla - Java Beginners
in .js file and i am calling that file in .jsp file as but the script... that both the html file and the js file should be in same location. HTML file JS file function onPress(){ alert("i m in another
q - JSP-Servlet
and at runtime it save in .js file from that we show data in html control like... of data is save in .js file though repititive value is shown in dropdown control... it should first clear the data from .js file and then reload the data again  
how to invoket javascript function in JSP - JSP-Interview Questions
how to invoket javascript function in JSP  Dear Sir, my question is how to invoke javascript function written in .js file into our JSP. using which tag in JSP this is possible
Web Page Transaction
Web Page Transaction  Hello sir, i want to add an Effective page transaction when i go to my home page to other page in js...plllzzz help me...rppy soon
javascript - XML
javascript  HI, Greetings.... I want to call javascript file i.e. ".js" from xml file. If it is possible tell me how to do that. and i want to know how to call javascript function from xml... Please help me in this regard
Cross platform browser question - Java Beginners
-browser (works in Firefox and MS IE) web page using anonymous JS methods
java - Java Beginners
java   how to include crystel report to a java web project.I am using eclipse ide, my friend give some files(.js files) to me ,but don't know how to use it. can any one help me
XSS attack
XSS attack  I wish to know about XSS attack. At our server the some of the web pages such as index.php and login.php are getting infected with malicious script. Some script / JS is getting injected. I clean the file uploaded
Try it Editor
Try it Editor  Hello sir...actually i want to add an html,css & js editor like in w3 school try it editor 1.5....can you tell me how i can add it..pllz plzzz rppy soon
JSLT, alternative to XSLT
structure is: template[js]template{inline-xpath}[js]template. All code (13kb js/390
Themeroller
: /css/ /development-bundle/ /js/ index.html...="js/jquery-1.4.2.min.js"> </script> <script type="text/javascript" src="js/jquery-ui-1.8.4.custom.min.js"> <
Spring MVC JQuery Integration
your js file in your view JSP file or adding any jQuery plug in using... locate the .js file SOLUTION You can eliminate the above problem by adding .js
ExtJS formerly called YUI - WebSevices
in Ext js. We will upload the example of Ext js tomorrow. Check it tomorrow
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 Explorer. eg: new.js------ function onPress
syntax problem - Java Beginners
.(that is classname not equal to 'check').I have to use this check in side a js file
dojo check tree code - Ajax
: Could not load 'dojox.data.QueryReadStore'; last tried '__package__.js
Multiarray concept
Multiarray concept  i have 4 text box in html page, when i click new it would want to add another 4 like that ,i will go on like this? when i click delete last four buttons want to delete from it. how i can do this using js
filter and display html table data using ajax - Ajax
filter and display html table data using ajax  Hi i am stuck up at a situation where i have a jsp page from where the control goes to the .js file calling the ajax function called retrieveURL.from here goes
Displaying different portions of a page subsequently on the basis of action
Displaying different portions of a page subsequently on the basis of action  Suppose in Report.jsp there are two text fields From Date: and To Date: with js calender beside these and a SEARCH Button(When the page initially loads
QuTags - PHP Style AJAX
QuTags - PHP Style AJAX       PHP & C Module that is AJAX for PHP, with no JAX. You don't even have to know what AJAX or JavaScript is about. QuTags requires no knowledge of JS/XML
Convert To Java Program - Java Beginners
the value you want delete: "); scanf("%d",&s); for(j=0; jro;js--) { array[js]=array[js-1]; }array[ro]=don; main(); } } void
servlet session - JSP-Servlet
that called the servlet: like in JS we can call a previous page
Data Generator
friendly and JS-enabled. A large sum of data types is available
jQueryWTP
. step8:open a html file,edit js content. Click on this link to get more detail
How to raise an event on a flash mp3 player after 30 seconds from starting song..?
) with full source code (.fla, .swf, .js) files. I need to raise an event and call

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.