Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
New Feature: Community Sites:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
|
Javascript Validations
|
//************************************************************** //Author/Coded By :-CHALMAL SEETARAM //Module Name :-FormValidations.js //Type :-Include file //Created On :-20/02/2006 //Last Modified On :-28/02/2006 //Functionality :-Generel functions to validate all Fields //**************************************************************
var AlertMsg=""; var Control="";
//-----1.Use to Check BlankSpaces ---------------- function IsEmpty(str){ for (var i = 0; i < str.length; i++) { if (" " != str.charAt(i)) return false; else {return true;} } } function PopUpMsg() { alert("HI"); }
//-------2.Use This Function To Validate For Characters ------------- function ValidateCharacters(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName) l=ObjectName.value.length; if (Required==true || (Required==false && l>0)){ if (IsEmpty(ObjectName.value)){ AlertMsg += "Information must be entered in " + ObjectCaption;//my Edit //alert("Information must be entered in " + ObjectCaption);//my Edit Control=Control+objName+"-"; ObjectName.focus();//my Edit ObjectName.select(); //Information(AlertMsg); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n";//my Edit //alert("Information must be entered in " + ObjectCaption);//my Edit Control=Control+objName+"-"; ObjectName.focus();//my Edit ObjectName.select(); //Information(AlertMsg); return false; } for (var i = 0; i < ObjectName.value.length; i++){ var ch=ObjectName.value.charAt(i); if ((ch < "a" || ch > "z") && (ch < "A" || ch > "Z")){ AlertMsg +=ObjectCaption +" must contain only alphabets. Please re-enter.\n";//my Edit //alert(ObjectCaption +" must contain only alphabets. Please re-enter \n")//my Edit Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Characters \n";//my Edit //alert(ObjectCaption + " Should not exceed " + MaxLength + " Characters ");//my Edit Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if (MinLength > 0){ if (ObjectName.value.length < MinLength){ AlertMsg +=ObjectCaption + " Can't be less than "+ MinLength + " Characters\n";//my Edit //alert(ObjectCaption + " Can't be less than "+ MinLength + " Characters");//my Edit Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } }if(AlertMsg.length > 0){Information(AlertMsg);return false;} else{return true;} // if(AlertMsg.length > 0){Information(AlertMsg);return false;} // else{return true;} }
//-------3.Use This Function To Check Field Length ------------- function ValidateLength(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName) l=ObjectName.value.length; if (Required==true || (Required==false && l>0)){ if (IsEmpty(ObjectName,ObjectCaption)){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Characters \n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } if (MinLength > 0){ if (ObjectName.value.length < MinLength){ AlertMsg +=ObjectCaption + " Can't be less than "+ MinLength + " Characters\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } } } else{return true;} }
//----------4.Use this function To Validate Numeric Values-------------- // MinLength should be 0 when no minimum length validation required function ValidateNumbers(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName) l=ObjectName.value.length; if (Required==true || (Required==false && l>0)){ if (IsEmpty(ObjectName,ObjectCaption)){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } if(ObjectName.value == 0){ //alert(ObjectCaption + "Should not be all Zeroes"); AlertMsg +=ObjectCaption + "Should not be all Zeroes" + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } for (var i = 0; i < ObjectName.value.length; i++){ if (ObjectName.value.charAt(i) < '0' || ObjectName.value.charAt(i) > '9'){ //alert("Enter a valid numeric value In " + ObjectCaption + " Field(#####)") AlertMsg +=ObjectCaption +" must contain digits between 0 and 9. Please re-enter.\n"; //alert(ObjectCaption +" must contain digits between 0 and 9. Please re-enter.\n") Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Numbers \n"; //alert(ObjectCaption + " Should not exceed " + MaxLength + " Numbers "); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } if (MinLength > 0){ if (ObjectName.value.length < MinLength){ AlertMsg +=ObjectCaption + " Can't be less than "+ MinLength + " Numbers\n"; //alert(ObjectCaption + " Can't be less than "+ MinLength + " Numbers"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } } else{return true;} if(AlertMsg.length > 0){Information(AlertMsg);return false;} else{return true;} }
//--------5.Use This function Validate For Phone Numbers ----------- //----here the Format are "nnn-nnn-nnnn" ,"(nnn)nnn-nnnn" and "nnnnnnnnnn". //--- if you want another format just add format in regexp of the below function. function ValidatePhoneNumbers(ObjectName,ObjectCaption,MaxLength,Format,Required){ var regexp = "" objName=ObjectName; ObjectName=eval(ObjectName) l=ObjectName.value.length; //var regexp = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4})$/; if (Required==true || (Required==false && l>0)){ if (Format == "nnn-nnn-nnnn"){ regexp = /^(\d{3}-\d{3}-\d{4})$/; } else if (Format == "(nnn)nnn-nnnn"){ regexp = /^(\(\d{3}\)\d{3}-\d{4})$/; } else if (Format == "nnnnnnnnnn"){ regexp = /^(\d{10})$/; } if (regexp == ""){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else{ if (regexp.test(ObjectName.value)==false){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } } } if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Characters \n" //alert(ObjectCaption + " Should not exceed " + MaxLength + " Characters "); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } }
//-----------6.Use This Function To Validate Date--------------------
function ValidateDate(ObjectName,ObjectCaption,MaxLength,Format,Required){ var regexp = "" ObjectName=eval(ObjectName) l=ObjectName.value.length; da=ObjectName.value if ((Required==true) || (Required==false && l>0)){ if ((Format == "dd/mm/yyyy")||(Format == "mm/dd/yyyy")){ regexp = /^(\d{2}\/\d{2}\/\d{4})$/; } if (regexp == ""){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } else{ if (regexp.test(ObjectName.value)==false){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } if (Format == "dd/mm/yyyy"){dd=da.substr(0,2);mm=da.substr(3,2);yy=da.substr(6,4)} //if (Format == "mm/dd/yyyy"){dd=da.substr(3,2);mm=da.substr(0,2);yy=da.substr(6,4)} if ((dd>31 || mm>12) || ((mm == 1 || mm == 3 || mm ==5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd > 31) || ((mm == 04 || mm == 06 || mm == 9 || mm == 11) && dd > 30) || ((yy % 4) == 0 && mm==2 && dd > 29) || ((yy % 4) != 0 && mm==2 && dd > 28)){ AlertMsg += "Invalid Date entered in " + ObjectCaption + " \n"; //alert(ObjectCaption + " my1 is invalid date") ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } var currentDate=new Date(); //alert(currentDate); curDate=currentDate.getDate(); curMonth=currentDate.getMonth()+1; curYear=currentDate.getFullYear(); if(yy>=curYear){ if(mm>=curMonth){ if(dd>curDate || dd<=curDate){ AlertMsg += "Invalid Date entered in " + ObjectCaption + " \n"; //alert(ObjectCaption + " my2 is invalid date") ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } } } if(AlertMsg.length > 0){Information(AlertMsg);return false;} else{return true;} }
//-----------7. Use this Function to Validate Email-------------------------- function ValidateEmail(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName) l=ObjectName.value.length; txt=ObjectName.value; pos1=txt.indexOf("@"); pos2=txt.indexOf("."); //alert(pos2); var str1 = txt.split("@"); var str2 = txt.split("."); alert(str2[1]); alert(str2); //var dotpos1 = str2.indexOf("."); alert(pos1); //alert(strDom[2]); if(str2[1].length<=2) { var strDom = str2[1].split("."); //alert(strDom[0]); } var ch=txt.charAt(0); if (Required == true || (Required==false && l>0)){ if (IsEmpty(ObjectName.value)){ AlertMsg += "Information must be entered in " + ObjectCaption; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if ((ch < "a" || ch > "z") && (ch < "A" || ch > "Z")){ AlertMsg +=ObjectCaption + " address seems wrong, must begin with an alphabet.\n" //alert(ObjectCaption + " address seems wrong, must begin with an alphabet"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } for (var i = pos1+1; i < pos2; i++){ var ch=ObjectName.value.charAt(i); if ((ch < "a" || ch > "z") && (ch < "A" || ch > "Z") && (ch < '0' || ch > '9')){ AlertMsg +=ObjectCaption + " address seems wrong. Please check the suffix and '@' sign.\n" //alert(ObjectCaption +" address seems wrong. Please check the suffix and '@' sign.\n"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } } if (txt.indexOf("@")<3){ AlertMsg +=ObjectCaption + " address seems wrong. Please check the prefix and '@' sign.\n" //alert(ObjectCaption + " address seems wrong. Please check the prefix and '@' sign."); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5) &&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5) &&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)&& (txt.indexOf(".co.in")<5)){ AlertMsg +=ObjectCaption + " address seems wrong. Please check the suffix for accuracy. (It should include a .com, .co.in, .edu, .net, .org, .gov or .mil)\n" //alert(ObjectCaption + " address seems wrong. Please check the suffix for accuracy. (It should include a .com, .edu, .net, .org, .gov or .mil)"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Characters \n"; //alert(ObjectCaption + " Should not exceed " + MaxLength + " Characters "); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } else if (MinLength > 0){ if (ObjectName.value.length < MinLength){ AlertMsg +=ObjectCaption + " Can't be less than "+ MinLength +" Characters\n"; //alert(ObjectCaption + " Can't be less than "+ MinLength +" Characters"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } } else if((pos2-pos1)<5){ AlertMsg +=ObjectCaption + " address seems wrong. Please check the suffix for accuracy."; //alert(ObjectCaption + " address seems wrong. Please check the suffix for accuracy"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } } else{return true;} }
//-------8. Use This Function to Verify the Password entered in Two Password Box-------- function VerifyPWD(ObjectName1,ObjectName2,CaseSensitive) { objName=ObjectName; ObjectName1=eval(ObjectName1) ObjectName2=eval(ObjectName2) if (IsEmpty(ObjectName1.value)) { alert("Information must be entered in " + ObjectName1.name); Control=Control+objName+"-"; ObjectName1.focus(); ObjectName1.select(); return false; } if (IsEmpty(ObjectName2.value)) { alert("Information must be entered in " + ObjectName2.name); Control=Control+objName+"-"; ObjectName2.focus(); ObjectName2.select(); return false; } if (CaseSensitive==false) { if ((ObjectName1.value.toUpperCase) != (ObjectName2.value.toUpperCase)) { alert(ObjectName2.name + " not match with "+ ObjectName1.name); Control=Control+objName+"-"; ObjectName2.focus(); ObjectName2.select(); return false; } else {return true;} } else { if (ObjectName1.value != ObjectName2.value) { alert(ObjectName2.name + " not match with "+ ObjectName1.name); Control=Control+objName+"-"; ObjectName2.focus(); ObjectName2.select(); return false; } else { return true; } } }
//verifies that card number matches the card type function CheckCardNumber(FormName){ var accountNumber = FormName.AccountNumber.value; var cardType = FormName.cardtype.options[FormName.cardtype.selectedIndex].value; var acctNumDigit = accountNumber.charAt(0); var normalizedAccount = accountNumber //stripCharsInBag(accountNumber); if ((acctNumDigit == "6") && (cardType == "004")){ accountNumber = ReformatCreditCard(normalizedAccount); return true; } else if ((acctNumDigit == "5") && (cardType == "002")){ accountNumber = ReformatCreditCard(normalizedAccount); return true; } else if ((acctNumDigit == "4") && (cardType == "001")){ accountNumber = ReformatCreditCard(normalizedAccount); return true; } else if ((acctNumDigit == "3") && (cardType == "003")){ accountNumber = ReformatCreditCard(normalizedAccount); return true; } else{ alert("The card number does not match the card type. Please re-enter."); FormName.AccountNumber.focus(); FormName.AccountNumber.select(); return false; }//end if }// end checkCardNumber
function ReformatCreditCard(accountNumber){ return (Reformat (accountNumber, "", 4, "", 4, "", 4, "", 4)) } function Reformat (s){ var arg; var sPos = 0; var resultString = ""; for (var i = 1; i < Reformat.arguments.length; i++) { arg = Reformat.arguments[i]; if (i % 2 == 1) resultString += arg;
else { resultString += s.substring(sPos, sPos + arg); sPos += arg; //alert(sPos); } } return resultString; }
function CheckDate(FormName){ var month = FormName.expirationmonth.options[FormName.expirationmonth.selectedIndex].value - 1; var year = FormName.expirationyear.options[FormName.expirationyear.selectedIndex].value; var date = new Date(year, month, 31); var now = new Date(); var diff = date.getTime() - now.getTime(); if (diff <= 0){ alert("Your credit has expired. Please use another card."); return false; } else {return true}; }//end CheckDate
//This Function is Used to Trap the key strokes for Number entries //The function filterDataType( cntrlName, dataType ) takes 2 arguments, //the first being the control object and the second the data type which can have the // values 'Int', 'Flt' or 'Dt',or 'Dt1' which specify the Data types Integer, //Float or Date and Date(mm/dd) respectively.
function filterDataType( cntrlName, dataType ) { if ( dataType == "Int" ) { if ( ( window.event.keyCode < 48 ) || ( window.event.keyCode > 57 ) ) window.event.keyCode = 0 } else if ( dataType == "Flt" ) { if ( window.event.keyCode == 46 ) { if ( cntrlName.value.indexOf(".") >= 0 ) window.event.keyCode = 0 } else { if ( window.event.keyCode < 48 || window.event.keyCode > 57 ) window.event.keyCode = 0 else if ( (cntrlName.value.indexOf(".") >= 0 )&&( cntrlName.value.length >= ( cntrlName.value.indexOf(".") + 3 ) ) ) window.event.keyCode = 0 } } else if ( dataType == "Dt" ) { kyCd = window.event.keyCode if ( window.event.keyCode == 45 ) kyCd = 47 if ( kyCd == 47 ) { if( cntrlName.value.length == 0 ) window.event.keyCode = 0 else if( ( cntrlName.value.length > 0 ) && ( cntrlName.value.indexOf("/") != cntrlName.value.lastIndexOf("/") ) ) window.event.keyCode = 0 else if ( cntrlName.value.length == ( cntrlName.value.indexOf("/") + 1 ) ) window.event.keyCode = 0 else window.event.keyCode = 47 } else { if ( window.event.keyCode < 48 || window.event.keyCode > 57 ) window.event.keyCode = 0 else { if( ( cntrlName.value.length >= 2 ) && ( cntrlName.value.indexOf("/") < 0 ) ) cntrlName.value = cntrlName.value + "/" if( ( cntrlName.value.length >= ( cntrlName.value.indexOf("/") + 3 ) ) && ( cntrlName.value.lastIndexOf("/") < 3 ) ) cntrlName.value = cntrlName.value + "/" if( ( cntrlName.value.length > 0 ) && ( cntrlName.value.indexOf("/") != cntrlName.value.lastIndexOf("/") ) && ( cntrlName.value.length >= ( cntrlName.value.lastIndexOf("/") + 5 ) ) ) window.event.keyCode = 0 } } } else if ( dataType == "Dt1" ) { kyCd = window.event.keyCode if ( window.event.keyCode == 45 ) kyCd = 47 if ( kyCd == 47 ) { if( cntrlName.value.length == 0 ) window.event.keyCode = 0 else if ( cntrlName.value.indexOf("/") >= 0 ) window.event.keyCode = 0 else window.event.keyCode = 47 } else { if ( window.event.keyCode < 48 || window.event.keyCode > 57 ) window.event.keyCode = 0 else { if( ( cntrlName.value.length >= 2 ) && ( cntrlName.value.indexOf("/") < 0 ) ) cntrlName.value = cntrlName.value + "/" if ( (cntrlName.value.indexOf("/") >= 0 )&&( cntrlName.value.length >= ( cntrlName.value.indexOf("/") + 3 ) ) ) window.event.keyCode = 0 } } } }
//This Function is Used to Dispaly Popup window function OpenWindow(sLink){ wndHelp = window.open(sLink,"HelpWindow","resizable=yes,menubar=yes,status=yes,scrollbars=yes,alwaysRaised=yes,width=600"); }
//-----------6.Use This Function To Validate Date--------------------
function ValidateDate1(ObjectName,ObjectCaption,MaxLength,Format,Required){ var regexp = "" ObjectName=eval(ObjectName) l=ObjectName.value.length; da=ObjectName.value if ((Required==true) || (Required==false && l>0)){ if ((Format == "dd/mm/yyyy")||(Format == "mm/dd/yyyy")){ regexp = /^(\d{2}\/\d{2}\/\d{4})$/; } if (regexp == ""){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) ObjectName.focus(); ObjectName.select(); return false; } else{ if (regexp.test(ObjectName.value)==false){ AlertMsg +="Enter "+ ObjectCaption +" in "+ Format + "\n"; //alert("Enter "+ ObjectCaption +" in "+ Format) ObjectName.focus(); ObjectName.select(); return false; } } if (Format == "dd/mm/yyyy"){dd=da.substr(0,2);mm=da.substr(3,2);yy=da.substr(6,4)} //if (Format == "mm/dd/yyyy"){dd=da.substr(3,2);mm=da.substr(0,2);yy=da.substr(6,4)} if(dd == 0 || mm == 0 || yy <="1900"){ alert("Enter valid "+ ObjectCaption +" in the Format "+ Format) ObjectName.focus(); ObjectName.select(); return false; } if ((dd>31 || mm>12) || ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && dd > 31) || ((mm == 04 || mm == 06 || mm == 9 || mm == 11) && dd > 30) || ((yy % 4) == 0 && mm==2 && dd > 29) || ((yy % 4) != 0 && mm==2 && dd > 28)){ AlertMsg += "Invalid Date entered in " + ObjectCaption + " \n"; //alert(ObjectCaption + "my1 is invalid date") ObjectName.focus(); ObjectName.select(); return false; } } var currentDate=new Date(); curDate=currentDate.getDate(); curMonth=currentDate.getMonth()+1; curYear=currentDate.getFullYear(); if(yy>curYear) { AlertMsg += "Invalid Date entered in " + ObjectCaption + " field \n"; //alert(ObjectCaption + " my2 is invalid date") ObjectName.focus(); ObjectName.select(); return false; } else { if(dd>curDate || mm>=curMonth){ //alert(ObjectCaption + " my3 is invalid date") AlertMsg += "Invalid Date entered in " + ObjectCaption + " field \n"; ObjectName.focus(); ObjectName.select(); return false; } } } //-----------Use This Function To Validate Email-Id--------------------
function ValidateEmail1(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName) var l=ObjectName.value.length; var str=ObjectName.value; var atPos=str.indexOf('@'); //alert(atPos); //var pos2=txt.indexOf("."); // var str, l; // str = document.getElementById("E-mail").value; if (Required == true || (Required==false && l>0)){ if (IsEmpty(ObjectName.value)){ AlertMsg += "Information must be entered in " + ObjectCaption; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); return false; } else if(str.charAt(0)<'A' || str.charAt(0)>'Z' && str.charAt(0)<'a' || str.charAt(0)>'z' || str.charAt(0) == "." || str.charAt(0) == "_" ){ //alert(" address seems wrong, must begin with an alphabet" + ObjectCaption); AlertMsg +="address seems wrong, must begin with an alphabet " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Invalid Email....") //Information(AlertMsg); return false } if( atPos == -1){ //alert("Please Enter Correct " + ObjectCaption); AlertMsg += "Please Enter Correct " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; } var strtemp = str.split('@'); //alert(strtemp.length); if(strtemp.length>2 || strtemp.length==-1) { AlertMsg +="Invalid " + ObjectCaption + "\n" //alert("Invalid " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Invalid Email....") //Information(AlertMsg); return false } var atPos=str.indexOf('@')
var strMail=strtemp[0] l=strMail.length; if(strMail.charAt(l-1) == "." || strMail.charAt(l-1) == "_") { //alert("Invalid " + ObjectCaption + " re enter"); AlertMsg +="Invalid " + ObjectCaption + "\n" Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select();//alert("Enter Correct Mail-id"); //Information(AlertMsg); return false; } var i; for(i=0;i { if(strMail.charAt(i)<'A' || strMail.charAt(i)>'Z' && strMail.charAt(i)<'a' || strMail.charAt(i)>'z' ) { if(strMail.charAt(i)<'0' || strMail.charAt(i)>'9') { if(strMail.charAt(i) != "_" && strMail.charAt(i) != "." ) { //alert("Enter Correct " + ObjectCaption); AlertMsg +="Enter Correct " + ObjectCaption + "\n" Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Enter Correct Mail-id"); // Information(AlertMsg); return false; } } } } /*if(strMail.length>30) { //alert(" Too Many Parameters in User-id....."); alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); return false; }*/ var k, l; l = strMail.length; for (k=0; k { if( (strMail.charAt(k) == "_" && strMail.charAt(k-1) == "_") ||(strMail.charAt(k) == "." && strMail.charAt(k-1) == "_") || (strMail.charAt(k) == "_" && strMail.charAt(k-1) == ".")) { //alert("Enter Correct " + ObjectCaption); AlertMsg += "Incorrect " + ObjectCaption + " entered " + "re Enter " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Enter Correct Mail-id......"); //Information(AlertMsg); return false; } }
var eMail = strMail.split('.'); if(eMail.length > 2) { //alert("Enter Correct " + ObjectCaption); AlertMsg += "Incorrect " + ObjectCaption + " entered " + "re Enter " + ObjectCaption; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select();//alert("Enter Correct Mail-id...."); //Information(AlertMsg); return false; }
var strDom=strtemp[1].split('.') if(strDom.length<2) { // alert("Please Specify the Correct domain of your " + ObjectCaption); AlertMsg+="Please Specify the Correct domain of your " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Please Specify the Correct domain of your Mail id"); //Information(AlertMsg); return false; }
if(strDom[0].length < 3) { //alert("Please Specify the Correct domain of your " + ObjectCaption); AlertMsg+="Please Specify the Correct domain of your " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //alert("Please Specify the Correct domain of your Mail id"); //Information(AlertMsg); return false; }
var j, strdom = strDom[0]; for(j=0; j < strdom.length; j++) { if(strdom.charAt(j) < 'A' || strdom.charAt(j) > 'Z' && strdom.charAt(j) <'a' || strdom.charAt(j)>'z') { if(strdom.charAt(j) != "-") { //alert("Please Specify the Correct domain of your Mail id" + ObjectCaption); //AlertMsg +=" Please Specify the Correct domain of " + ObjectCaption "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select();//alert("Please Specify the Correct domain of your Mail id"); //Information(AlertMsg); return false; } } }
var dotPos=strtemp[1].indexOf('.') var strSuffix=strtemp[1].substring(dotPos+1,strtemp[1].length) if(strSuffix != "com" && strSuffix !="in" && strSuffix != "gov" && strSuffix != "net" && strSuffix != "org" && strSuffix != "mil" && strSuffix != "edu" && strSuffix != "co.in") { //alert(" address seems wrong. Please check the suffix for accuracy. (It should include a .com, .co.in, .edu, .net, .org, .gov or .mil) in \n" + ObjectCaption); AlertMsg += " address seems wrong. Please check the suffix for accuracy. (It should include a .com, .co.in, .edu, .net, .org, .gov or .mil) in \n " + ObjectCaption + "\n"; Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); //Information(AlertMsg); //alert(" address seems wrong. Please check the suffix for accuracy. (It should include a .com, .co.in, .edu, .net, .org, .gov or .mil)\n"); return false; } } if(AlertMsg.length > 0){Information(AlertMsg);return false;} else {return true;} } //-----------Use this function To Validate PIN CODE Values-------------- // MinLength should be 0 when no minimum length validation required function ValidatePinCode(ObjectName,ObjectCaption,MaxLength,MinLength,Required){ objName=ObjectName; ObjectName=eval(ObjectName); l=ObjectName.value.length; if (Required==true || (Required==false && l>0)){ if (IsEmpty(ObjectName,ObjectCaption)){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(AlertMsg); return false; } else if (ObjectName.value.length <= 0){ AlertMsg +="Information must be entered in " + ObjectCaption + "\n"; //alert("Information must be entered in " + ObjectCaption); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(AlertMsg); return false; } if(ObjectName.value.charAt(0)== '0'){ AlertMsg +=ObjectCaption +"'s first digit must not be 0. Please re-enter.\n" //alert(ObjectCaption +"'s first digit must not be 0. Please re-enter.\n") Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(AlertMsg); return false; } for (var i = 0; i < ObjectName.value.length; i++){ if (ObjectName.value.charAt(i) < '0' || ObjectName.value.charAt(i) > '9'){ AlertMsg +=ObjectCaption +" must contain digits between 0 and 9. Please re-enter.\n"; //alert(ObjectCaption +" must contain digits between 0 and 9. Please re-enter.\n") Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(Msg); return false; } } if (l>MaxLength){ AlertMsg +=ObjectCaption + " Should not exceed " + MaxLength + " Numbers \n"; //alert(ObjectCaption + " Should not exceed " + MaxLength + " Numbers "); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(Msg); return false; } if (MinLength > 0){ if (ObjectName.value.length < MinLength){ AlertMsg +=ObjectCaption + " Can't be less than "+ MinLength + " Numbers\n"; //alert(ObjectCaption + " Can't be less than "+ MinLength + " Numbers"); Control=Control+objName+"-"; ObjectName.focus(); ObjectName.select(); Information(Msg); return false; } } } else{return true;} if(AlertMsg.length > 0){Information(AlertMsg);return false;} else{return true;} }
function Information(Msg){ alert(Msg); }
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|