Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragini Shukla
js
4 Answer(s)      6 years and a month ago
Posted in : Java Beginners



Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
Configure Js request in Web.xml
Configure Js request in Web.xml  Hi all, I have 1 basic doubt,suppose i have 2 jsp,1 servlet,1 web.xml file.i need to redirect 1 page via servlet with help of web.xml file.Here just i need to redirect to mainCtrl.java
Help for website development on Angular JS
Help for website development on Angular JS  want to develop a website using angular JS. I am new to the platform or coding on angular JS. Can i update a database column and get that data uploaded on my webpage simultaneosuly
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
Easiest method for expiring the css and js headers
Easiest method for expiring the css and js headers  Hi, I have a website with many thousand users visiting per day. I have changes the css file and uploaded it on server. Now some user is getting the old css file. Let's know
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  
dynamic creation of multiple drop-down menus
dynamic creation of multiple drop-down menus  can anybody plz help me in coding for dynamic creation of multiple drop-down menus in a webpage using ajax/js/html/css
Advertisements
 

 

 

DMCA.com