Kshirod
Validation code
3 Answer(s)      4 years and 6 months ago
Posted in : Java Interview Questions

View Answers

November 28, 2008 at 3:44 AM


Hi friend,

code to solve the problem :

<script language="javascript" type="text/javascript">
function validateZIP() {
var val = document.passform.password.value;
if(!isAlphabetic(val))
{
alert("Please enter valid character [a-z][A-Z].");
document.passform.password.focus();
return false;
}
return true;

}

function isAlphabetic(val)
{
if (val.match(/^[a-zA-Z]+$/))
{
return true;
}
else
{
return false;
}
}


</script>
<form name="passform" onSubmit="return validateZIP();">
Password: <input type="password" size=30 name="password">
<input type=submit value="Submit">
</form>

For more information on Javascript visit to :

http://www.roseindia.net/javascript/

Thanks

December 1, 2008 at 11:21 PM


calendar.html
*************

<html>
<head>
<title>Java Script Calender Date Picker</title>
<meta http-equiv="Content-Type" content="text/html;">
<script language="javaScript"
type="text/javascript" src="calendar.js"></script>
<link href="calendar.css" rel="stylesheet" type="text/css">
<script>
function isNumberKey(value)
{
//alert('alok_pass1');
var charCode = value.which ? (value.which) : event.keyCode
if (charCode > 31 && (charCode < 47 || charCode > 57))
return false;
}
function Validate()
{
//alert('Inside Function');
//alert('check empty' :+((document.getElementById("txtFromDate").value)!=""));
//if ((trim(document.getElementById("txtFromDate").value)!="") && (trim(document.getElementById("txtToDate").value) !=""))
//{
var strFromDate = document.getElementById("txtFromDate").value;
//alert('FROM_DATE-1 :'+strFromDate );
var dayPartFromDate = parseInt(strFromDate.substring(0,2),10);
var monPartFromDate = parseInt(strFromDate.substring(3,5),10);
var yearPartFromDate = parseInt(strFromDate.substring(6,10),10);
var dtFrom = new Date(yearPartFromDate, monPartFromDate-1, dayPartFromDate);

var strToDate = document.getElementById("txtToDate").value;
var dayPartToDate = parseInt(strToDate.substring(0,2),10);
var monPartToDate = parseInt(strToDate.substring(3,5),10);
var yearPartToDate = parseInt(strToDate.substring(6,10),10);
var dtTo = new Date(yearPartToDate, monPartToDate-1, dayPartToDate);

//alert('dtFrom :'+dtFrom );
//alert('dtTo :'+dtTo );

if(dtFrom > dtTo)
{
alert("From Date must be less than To Date");
return false;
}
}
//}

</script>
</head>
<body>
<form>
From_Date : <input type="text" name="txtFromDate"><a href="#"
onClick="setYears(1947, 2008);
showCalender(this, 'txtFromDate');">
<img src="calender.png"></a>

To_Date : <input type="text" name="txtToDate"><a href="#"
onClick="setYears(1947, 2008);
showCalender(this, 'txtToDate');">
<img src="calendar.jpeg"></a>

<input type="button" onclick="Validate()" value="Compare 2 Dates">


</form>

<!-- Calender Script -->

<table id="calenderTable">
<tbody id="calenderTableHead">
<tr>
<td colspan="4" align="center">
<select onChange="showCalenderBody(
createCalender(document.getElementById('selectYear').value,
this.selectedIndex, false));"
id="selectMonth">
<option value="0">Jan</option>
<option value="1">Feb</option>
<option value="2">Mar</option>
<option value="3">Apr</option>
<option value="4">May</option>
<option value="5">Jun</option>
<option value="6">Jul</option>
<option value="7">Aug</option>
<option value="8">Sep</option>
<option value="9">Oct</option>
<option value="10">Nov</option>
<option value="11">Dec</option>
</select>
</td>
<td colspan="2" align="center">
<select onChange="showCalenderBody(createCalender(this.value,
document.getElementById('selectMonth').selectedIndex, false));"
id="selectYear">
</select>
</td>
<td align="center">
<a href="#" onClick="closeCalender();">
<font color="#003333" size="+1">X</font>
</a>
</td>
</tr>
</tbody>
<tbody id="calenderTableDays">
<tr style="">
<td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td>
<td>Thu</td><td>Fri</td><td>Sat</td>
</tr>
</tbody>
<tbody id="calender"></tbody>
</table>

<!-- End Calender Script -->

</body>
</html>

December 1, 2008 at 11:22 PM


calendar.html
****************
<html>
<head>
<title>Java Script Calender Date Picker</title>
<meta http-equiv="Content-Type" content="text/html;">
<script language="javaScript"
type="text/javascript" src="calendar.js"></script>
<link href="calendar.css" rel="stylesheet" type="text/css">
<script>
function isNumberKey(value)
{
//alert('alok_pass1');
var charCode = value.which ? (value.which) : event.keyCode
if (charCode > 31 && (charCode < 47 || charCode > 57))
return false;
}
function Validate()
{
//alert('Inside Function');
//alert('check empty' :+((document.getElementById("txtFromDate").value)!=""));
//if ((trim(document.getElementById("txtFromDate").value)!="") && (trim(document.getElementById("txtToDate").value) !=""))
//{
var strFromDate = document.getElementById("txtFromDate").value;
//alert('FROM_DATE-1 :'+strFromDate );
var dayPartFromDate = parseInt(strFromDate.substring(0,2),10);
var monPartFromDate = parseInt(strFromDate.substring(3,5),10);
var yearPartFromDate = parseInt(strFromDate.substring(6,10),10);
var dtFrom = new Date(yearPartFromDate, monPartFromDate-1, dayPartFromDate);

var strToDate = document.getElementById("txtToDate").value;
var dayPartToDate = parseInt(strToDate.substring(0,2),10);
var monPartToDate = parseInt(strToDate.substring(3,5),10);
var yearPartToDate = parseInt(strToDate.substring(6,10),10);
var dtTo = new Date(yearPartToDate, monPartToDate-1, dayPartToDate);

//alert('dtFrom :'+dtFrom );
//alert('dtTo :'+dtTo );

if(dtFrom > dtTo)
{
alert("From Date must be less than To Date");
return false;
}
}
//}

</script>
</head>
<body>
<form>
From_Date : <input type="text" name="txtFromDate"><a href="#"
onClick="setYears(1947, 2008);
showCalender(this, 'txtFromDate');">
<img src="calender.png"></a>

To_Date : <input type="text" name="txtToDate"><a href="#"
onClick="setYears(1947, 2008);
showCalender(this, 'txtToDate');">
<img src="calendar.jpeg"></a>

<input type="button" onclick="Validate()" value="Compare 2 Dates">


</form>

<!-- Calender Script -->

<table id="calenderTable">
<tbody id="calenderTableHead">
<tr>
<td colspan="4" align="center">
<select onChange="showCalenderBody(
createCalender(document.getElementById('selectYear').value,
this.selectedIndex, false));"
id="selectMonth">
<option value="0">Jan</option>
<option value="1">Feb</option>
<option value="2">Mar</option>
<option value="3">Apr</option>
<option value="4">May</option>
<option value="5">Jun</option>
<option value="6">Jul</option>
<option value="7">Aug</option>
<option value="8">Sep</option>
<option value="9">Oct</option>
<option value="10">Nov</option>
<option value="11">Dec</option>
</select>
</td>
<td colspan="2" align="center">
<select onChange="showCalenderBody(createCalender(this.value,
document.getElementById('selectMonth').selectedIndex, false));"
id="selectYear">
</select>
</td>
<td align="center">
<a href="#" onClick="closeCalender();">
<font color="#003333" size="+1">X</font>
</a>
</td>
</tr>
</tbody>
<tbody id="calenderTableDays">
<tr style="">
<td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td>
<td>Thu</td><td>Fri</td><td>Sat</td>
</tr>
</tbody>
<tbody id="calender"></tbody>
</table>

<!-- End Calender Script -->

</body>
</html>




calender.js
*****************
**************
// Array of max days in month in a year and in a leap year
monthMaxDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
monthMaxDaysLeap= [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
hideSelectTags = [];

function getRealYear(dateObj)
{
return (dateObj.getYear() % 100) +
(((dateObj.getYear() % 100) < 39) ? 2000 : 1900);
}

function getDaysPerMonth(month, year)
{
/*
Check for leap year. These are some conditions
to check year is leap year or not...
1.Years evenly divisible by four are normally
leap years, except for...
2.Years also evenly divisible by 100 are not
leap years, except for...
3.Years also evenly divisible by 400 are
leap years. */
if ((year % 4) == 0)
{
if ((year % 100) == 0 && (year % 400) != 0)
return monthMaxDays[month];


return monthMaxDaysLeap[month];
}
else
return monthMaxDays[month];
}

function createCalender(year, month, day)
{
// current Date
var curDate = new Date();
var curDay = curDate.getDate();
var curMonth = curDate.getMonth();
var curYear = getRealYear(curDate)

// if a date already exists, we calculate some values here
if (!year)
{
var year = curYear;
var month = curMonth;
}

var yearFound = 0;
for (var i=0; i<document.getElementById('selectYear').options.length;
i++)
{
if (document.getElementById('selectYear').options[i].value
== year)
{
document.getElementById('selectYear').selectedIndex =
i;
yearFound = true;
break;
}
}
if (!yearFound)
{
document.getElementById('selectYear').selectedIndex = 0;
year = document.getElementById('selectYear').options[0].value;
}
document.getElementById('selectMonth').selectedIndex = month;

// first day of the month.
var fristDayOfMonthObj = new Date(year, month, 1);
var firstDayOfMonth = fristDayOfMonthObj.getDay();

continu = true;
firstRow = true;
var x = 0;
var d = 0;
var trs = []
var ti = 0;
while (d <= getDaysPerMonth(month, year))
{
if (firstRow)
{
trs[ti] = document.createElement("TR");
if (firstDayOfMonth > 0)
{
while (x < firstDayOfMonth)
{
trs[ti].appendChild(document.createElement
("TD"));
x++;
}
}
firstRow = false;
var d = 1;
}
if (x % 7 == 0)
{
ti++;
trs[ti] = document.createElement("TR");
}
if (day && d == day)
{
var setID = 'calenderChoosenDay';
var styleClass = 'choosenDay';
var setTitle = 'this day is currently selected';
}
else if (d == curDay && month == curMonth && year == curYear)
{
var setID = 'calenderToDay';
var styleClass = 'toDay';
var setTitle = 'this day today';
}
else
{
var setID = false;
var styleClass = 'normalDay';
var setTitle = false;
}
var td = document.createElement("TD");
td.className = styleClass;
if (setID)
{
td.id = setID;
}
if (setTitle)
{
td.title = setTitle;
}
td.onmouseover = new Function('highLiteDay(this)');
td.onmouseout = new Function('deHighLiteDay(this)');
if (targetEl)
td.onclick = new Function(
'pickDate('+year+', '+month+', '+d+')'
);
else
td.style.cursor = 'default';
td.appendChild(document.createTextNode(d));
trs[ti].appendChild(td);
x++;
d++;
}
return trs;
}

function showCalender(elPos, tgtEl)
{
targetEl = false;

if (document.getElementById(tgtEl))
{
targetEl = document.getElementById(tgtEl);
}
else
{
if (document.forms[0].elements[tgtEl])
{
targetEl = document.forms[0].elements[tgtEl];
}
}
var calTable = document.getElementById('calenderTable');

var positions = [0,0];
var positions = getParentOffset(elPos, positions);
calTable.style.left = positions[0]+'px';
calTable.style.top = positions[1]+'px';

calTable.style.display='block';

var matchDate = new RegExp('^([0-9]{2})-([0-9]{2})-([0-9]{4})$');
var m = matchDate.exec(targetEl.value);
if (m == null)
{
trs = createCalender(false, false, false);
showCalenderBody(trs);
}
else
{
if (m[1].substr(0, 1) == 0)
m[1] = m[1].substr(1, 1);
if (m[2].substr(0, 1) == 0)
m[2] = m[2].substr(1, 1);
m[2] = m[2] - 1;
trs = createCalender(m[3], m[2], m[1]);
showCalenderBody(trs);
}

hideSelect(document.body, 1);
}
function showCalenderBody(trs)
{
var calTBody = document.getElementById('calender');
while (calTBody.childNodes[0])
{
calTBody.removeChild(calTBody.childNodes[0]);
}
for (var i in trs)
{
calTBody.appendChild(trs[i]);
}
}
function setYears(sy, ey)
{
// current Date
var curDate = new Date();
var curYear = getRealYear(curDate);
if (sy)
startYear = curYear;
if (ey)
endYear = curYear;
document.getElementById('selectYear').options.length = 0;
var j = 0;
for (y=ey; y>=sy; y--)
{
document.getElementById('selectYear')[j++] = new Option(y, y);
}
}
function hideSelect(el, superTotal)
{
if (superTotal >= 100)
{
return;
}

var totalChilds = el.childNodes.length;
for (var c=0; c<totalChilds; c++)
{
var thisTag = el.childNodes[c];
if (thisTag.tagName == 'SELECT')
{
if (thisTag.id != 'selectMonth' && thisTag.id != 'selectYear')
{
var calenderEl = document.getElementById('calenderTable');
var positions = [0,0];
var positions = getParentOffset(thisTag, positions); // nieuw
var thisLeft = positions[0];
var thisRight = positions[0] + thisTag.offsetWidth;
var thisTop = positions[1];
var thisBottom = positions[1] + thisTag.offsetHeight;
var calLeft = calenderEl.offsetLeft;
var calRight = calenderEl.offsetLeft + calenderEl.offsetWidth;
var calTop = calenderEl.offsetTop;
var calBottom = calenderEl.offsetTop + calenderEl.offsetHeight;

if (
(
// check if it overlaps horizontally
(thisLeft >= calLeft && thisLeft <= calRight)
||
(thisRight <= calRight && thisRight >= calLeft)
||
(thisLeft <= calLeft && thisRight >= calRight)
)
&&
(
// check if it overlaps vertically
(thisTop >= calTop && thisTop <= calBottom)
||
(thisBottom <= calBottom && thisBottom >= calTop)
||
(thisTop <= calTop && thisBottom >= calBottom)
)
)
{
hideSelectTags[hideSelectTags.length] = thisTag;
thisTag.style.display = 'none';
}
}

}
else if(thisTag.childNodes.length > 0)
{
hideSelect(thisTag, (superTotal+1));
}
}
}
function closeCalender()
{
for (var i=0; i<hideSelectTags.length; i++)
{
hideSelectTags[i].style.display = 'block';
}
hideSelectTags.length = 0;
document.getElementById('calenderTable').style.display='none';
}
function highLiteDay(el)
{
el.className = 'hlDay';
}
function deHighLiteDay(el)
{
if (el.id == 'calenderToDay')
el.className = 'toDay';
else if (el.id == 'calenderChoosenDay')
el.className = 'choosenDay';
else
el.className = 'normalDay';
}
function pickDate(year, month, day)
{
month++;
day = day < 10 ? '0'+day : day;
month = month < 10 ? '0'+month : month;
if (!targetEl)
{
alert('target for date is not set yet');
}
else
{
targetEl.value= day+'-'+month+'-'+year;
closeCalender();
}
}
function getParentOffset(el, positions)
{
positions[0] += el.offsetLeft;
positions[1] += el.offsetTop;
if (el.offsetParent)
positions = getParentOffset(el.offsetParent, positions);
return positions;
}









Related Pages:
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
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
it goes to another folder.) this is my code i used this method... Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class...; in this code i have to get error when sno,date,custmername,contactno
validation
validation  when user enter course to follow,should have pre requirements. This is my code if(document.application1.courseCode1.value ==1) { frmvalidator.addValidation("subject1","shouldselchk=biology","Should
Validation
Validation  Here is my form and what code should i write for validating it? - <form action="test4.jsp"> <ul> <b>User ID</b> :<input type="text" name="userid">
Validation
Validation  Here is my form and what code should i write for validating it? - <form action="test4.jsp"> <ul> <b>User ID</b> :<input type="text" name="userid">
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code for the following fields 1)Name 2)Email 3)Mobile 4)City 5)State 6)Product type 7...,email required etc) Kindly please send me the code as soon as possible
Javascript validation code
Javascript validation code  Hi, I need a javascript validation code for the following fields 1)Name 2)Email 3)Mobile 4)City 5)State 6)Product type 7.....it should display enter the field required Kindly please send me the code
date validation
date validation  sir, pls provide date validation code in javascript..we want to include it into our master form..   Please visit the following link: http://www.roseindia.net/mysql/datevalidation.shtml
Validation code - Java Interview Questions
Validation code  Hi, Anyone can please send me a javascript function for password filed validation (the field will only take characters as input not other). Thanx in advance  Hi friend, code to solve the problem
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... be done ? what change in the code should be made plz help.............. i
combox validation javascript code - JSP-Servlet
combox validation javascript code  hiiiiiii, I want a javascript code for combobox field validation for my Lotus Notes web page.... thnx  Hi This is the source code of combobox validation in javascript
javascript validation
javascript validation  my problem is following code is my form i want validation and for email field it will check formate useing regularexpressions...;html    Email Validation function checkEmail
String Validation
String Validation changing password  Hi. I have a HTML coding in that I have to check whether the value given in the 2 password fields are same... a message.   Here is a code that accepts the current password, New
form validation
want validation code,username minimum 8 char,password length must >6,and one
Email Validation code - Java Interview Questions
Email Validation code  Can anybody tell me how to write email validation code using java   Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/java/core/regularExpressions.html Thanks
jsp validation
jsp validation  enter name-___ enter number-__ I want that the focus should not go to number till the time u have entered name. Means the number text should be disabled.. i require code
Form validation
Form validation  Hi Everyone Can someone assist me with a complete code to validate a form. e.g where the user must insert an ID number it should... be a dynamic function code e.g validate.js that I can link it to my jsp page. Your
javascript validation
button.. please send me the code for this as i am new to the dot net field
Time validation
project.   Here is a code that accepts the time in the format hh:mm
user validation
user validation  i hv just started with my lessons in jsp n also doin my final yr project in jsp.i m doin the login page & m stuck with a problem in validating the user.the code i hv written below doesnt redirect to the login
String Validation
;Here is a code that accepts the current password, New password and conform
String Validation
;Here is a code that accepts the current password, New password and conform
Password validation
Password validation  Hi. I have a change password form. In that i have to check the values given in the new password and confirm password are same or not. Please help.   Here is a code that accepts the current password
Password validation
Password validation  Hi. I have a change password form. In that i have to check the values given in the new password and confirm password are same or not. Please help.   Here is a code that accepts the current password
Password validation
Password validation  Hi. I have a change password form. In that i have to check the values given in the new password and confirm password are same or not. Please help.   Here is a code that accepts the current password
Password validation
Password validation  Hi. I have a change password form. In that i have to check the values given in the new password and confirm password are same or not. Please help.   Here is a code that accepts the current password
Password validation
is a code that accepts the current password, New password and conform password from
String Validation
.   Here is a code that accepts the current password, New password
Zip Code Validation - Java Interview Questions
Zip Code Validation  Hi, Anyone can please send me a javascript function of the following --> Indian postal Zip Code Validation (Only 6 digits, no characters allowed) --> Date Validation (From and To) From date
javascript for websites url validation
javascript for websites url validation  javascript for websites url validation   JavaScript Code for URL Validation **function isvalidurl(url) { return url.match(/^(ht|f)tps?:\/\/[a-z0-9-.]+.[a-z]{2,4}\/?([^\s<
struts client side validation
struts client side validation  how can i code for client side validation
validation
validation  validation
Please provide jquery inline form validation for the code
Please provide jquery inline form validation for the code   <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Student Form</title> <script type
Two Dates code validation - Date Calendar
Two Dates code validation  Hi Sir.I am using calender for two text... should be greater than date of birth.plz help me in code .  Hi Friend, Try the following code: function check(objName) { var datefield
Ajax form validation Example
Ajax form validation Example  Hi, I want to validate my ajax form. Please give me good code for Ajax form validation. Thanks   Hi, Read jQuery to validate Email Address tutorial. In this tutorial you will learn how
server side validation in struts
server side validation in struts  Hello sir, i want to do server side validation in struts based on 3 fields. those 3 field are BatchNo......This should be done through database...can u please tell me how to write code
simple javascript validation for numbers
simple javascript validation for numbers  simple javascript validation for register number   Here is a html code that accepts number from...; <title>Mobile number validation using regex</title> <script
postal address validation
address..we dont have any apt source code regards to postal address validation...so pls consider us and provide the valid source code
Spring Validation
Spring Validation In this tutorial you will see an example of how to perform validation in spring-core. The spring provide Validator interface for validation of object. The Validator inteface work parallel with the Errors object so
validation - JSP-Servlet
,jsp,beans demo of all these to facilitate how to write code... iam very... side validation and when you submit the form it passes the data to some file over...-validation. You may visit the following link to view the example : http
Login page validation on ipad
Login page validation on ipad  I am using userId & password labels and their corresponding textfield. Now I want to validate the details... the code or resorse for the same. Plz its urgent
data validation by maker and checker
data validation by maker and checker  My requirment is like ,an user will view some records in a jsp page,and two buttons will be there in that page... me full code. Thanks and Regards, Ujjal
Struts2 Validation Problem - Struts
Struts2 Validation Problem  Hi, How to validate field that should not accept multiple spaces in Struts2? Regards, Sandeep  Hi... the logic in this lines of code : blic String execute() throws Exception
jsp-oracle validation - JDBC
, Implement validation code. Insert into database function...jsp-oracle validation  Dear friends, my validation not takes place. can you please tell me where the code is wrong, because sometimes it validates
validation in java script
validation in java script  i have put this code for only entering...;& rn.charAt(i)<='9') { } else { alert("code must be an integer"); return... code that validate s the number. <html> <script> function validate
Validation in swing - Java Beginners
Validation in swing  I want to validate my swing program. If I didnt enter the field in text box a msgbox should have to appear that enter all the fields.  Hi Friend, Try the following code: import java.awt.
Javascript validation - Java Beginners
for the validation of Zip code,the problem is, when user enters the valid zip code... want that if user enters the valid zip code in first attempt then text box's background color should't change,if user enters invalid sip code then then text box's
Registration page with JavaScript Validation
Registration page with JavaScript Validation   HTML Registration page with JavaScript Validation - required source code   Registration page in HTML with JavaScript Validation source code <html> <head>

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.