js

Ads

 
 

Share on Google+Share on Google+

Ragini Shukla
js
4 Answer(s)      9 years ago
Posted in : Java Beginners
Ads
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
[email protected]



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.

Ads









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
Version of rhino>js dependency
List of Version of rhino>js dependency
Version of jaxme>jaxme-js dependency
List of Version of jaxme>jaxme-js dependency
Version of com.belteshazzar>junit-js dependency
List of Version of com.belteshazzar>junit-js dependency
Version of com.butor>butor-js dependency
List of Version of com.butor>butor-js dependency
Version of com.cognitect>transducers-js dependency
List of Version of com.cognitect>transducers-js dependency
Version of com.cognitect>transit-js dependency
List of Version of com.cognitect>transit-js dependency
Version of com.synhaptein>scalator-js dependency
List of Version of com.synhaptein>scalator-js dependency
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
Maven Dependency js >> 1.5R3
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.5R3 in your project
Maven Dependency js >> 1.5R4.1
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.5R4.1 in your project
Maven Dependency js >> 1.5R4-RC3
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.5R4-RC3 in your project
Maven Dependency js >> 1.6R1
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R1 in your project
Maven Dependency js >> 1.6R2
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R2 in your project
Maven Dependency js >> 1.6R3
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R3 in your project
Maven Dependency js >> 1.6R5
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R5 in your project
Maven Dependency js >> 1.6R6
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R6 in your project
Maven Dependency js >> 1.6R6-candidate2
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R6-candidate2 in your project
Maven Dependency js >> 1.6R7
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.6R7 in your project
Maven Dependency js >> 1.7R1
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.7R1 in your project
Maven Dependency js >> 1.7R2
You should include the dependency code given in this page to add Maven Dependency of rhino >> js version1.7R2 in your project
Version of com.lihaoyi>utest-js-plugin dependency
List of Version of com.lihaoyi>utest-js-plugin dependency
Version of com.marekkadek>rxscala-js-cats_sjs0.6_2.11 dependency
List of Version of com.marekkadek>rxscala-js-cats_sjs0.6_2.11 dependency
Version of com.marekkadek>rxscala-js-cats_sjs0.6_2.12 dependency
List of Version of com.marekkadek>rxscala-js-cats_sjs0.6_2.12 dependency
Version of be.tzbob>scala-js-snabbdom_sjs0.6_2.12 dependency
List of Version of be.tzbob>scala-js-snabbdom_sjs0.6_2.12 dependency
Version of cat.inspiracio>rhino-js-engine dependency
List of Version of cat.inspiracio>rhino-js-engine dependency
Version of cn.jhc>umeditor-vaadin-js dependency
List of Version of cn.jhc>umeditor-vaadin-js dependency