1- Empty Field Validation:- (To check whether a text field is empty or not)
function IsEmpty(aTextField) {
if ((aTextField.value.length==0)
(aTextField.value==null)) {
return true;
}
else { return false; }
}
////////////////////////////////////////////////
2- Numeric Validation:- (To check whether a text field contains Numeric Values)
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
////////////////////////////////////////////////
3- Aplphabet Validation:- (To check whether a text field contains Alphabetic Values)
function IsAlphabet(sText)
{
var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var IsAlpha=true;
var Char;
for (i = 0; i < sText.length && IsAlpha == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsAlpha= false;
}
}
return IsAlpha;
}
/////////////////////////////////////////////////////////////////////////
3- Email Address Validation:- (To check whether a text field contains valid email value)
function isValidEmail(str) {
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
No comments:
Post a Comment