client side validation 2
Javascript validation
validNum(formField,fieldLabel,required)
validRequired(formField,fieldLabel)
Trim(str)
LTrim(str)
RTrim(str)
function IsEmpty(ctrl,mess)
function validNum(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
if (!allDigits(formField.value))
{
alert('Please enter a number for the "' + fieldLabel
+'" field.');
formField.focus();
result = false;
}
}
return result;
}
function validRequired(formField,fieldLabel)
{
var result = true;
if (formField.value == "")
{
alert('Please enter a value for the "' + fieldLabel +'"
field.');
formField.value=Trim(formField.value);
//alert('d');
formField.focus();
result = false;
return result;
}
if (IsEmpty(formField,"Please enter a value for "+fieldLabel))
{
formField.value=Trim(formField.value);
result = false;
}
return result;
}
function Trim(str)
/*
PURPOSE: Remove trailing and leading blanks from our string.
*/
{
return RTrim(LTrim(str));
}
function LTrim(str)
{
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1) {
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
j++;
s = s.substring(j, i);
}
return s;
}
function RTrim(str)
{
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
var i = s.length - 1; // Get length of string
while (i > = 0 && whitespace.indexOf(s.charAt(i)) != -1)
i--;
s = s.substring(0, i+1);
}
return s;
}
function IsEmpty(ctrl,mess)
{
var name=ctrl.value;
for(i=0;i < name.length;i++)
{
if (name.charAt(i) !=" ")
return false;
}
alert(mess);
ctrl.focus();
return true;
}