Thursday, April 10, 2008

JavaScript functions As used in validation or client end

Copy paste in notepad and then read

// JScript File For Validations ( Called on page Registeration.aspx)
// Check url expression
function ChtUrl(){ var Url="^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$" var tempURL=document.getElementById("txtYourRefferedLink").value; if(tempURL.length >= 1) { var matchURL=tempURL.match(Url); if(matchURL==null) { alert("Web URL is not valid... For Example:- http://www.abcd.com"); document.getElementById("txtYourRefferedLink").value=""; document.getElementById("txtYourRefferedLink").focus(); return false; } }
}// end of function ChtUrl()
// ckh digit onlyfunction CheckNumber()
{
var key = event.keyCode;var keyStr = String.fromCharCode(key);
var keyNum = parseInt(keyStr);if(isNaN(keyNum))
{event.keyCode = '';
}
} // end chk
function msg() { var msgs='Mandatory fields cannot be left blank'; return msgs; } function validation() { debugger; var strMsg= msg(); //0 // 1 Mail validation //2 txtFirstName var strValue=document.getElementById('txtFirstName').value; if (document.getElementById('txtFirstName').value=="") { alert(strMsg); document.getElementById('txtFirstName').value=""; document.getElementById('txtFirstName').focus(); return false; } //3 txtLastName var strValue=document.getElementById('txtLastName').value; if (document.getElementById('txtLastName').value=="") { alert(strMsg); document.getElementById('txtLastName').value=""; document.getElementById('txtLastName').focus(); return false; } //4 txtScreenName var strValue=document.getElementById('txtScreenName').value; if (document.getElementById('txtScreenName').value=="") { alert(strMsg); document.getElementById('txtScreenName').value=""; document.getElementById('txtScreenName').focus(); return false; } //5 Location var strValue=document.getElementById('txtLocation').value; if (document.getElementById('txtLocation').value=="") { alert(strMsg); document.getElementById('txtLocation').value=""; document.getElementById('txtLocation').focus(); return false; } // 6 date of birth var strValue=document.getElementById('txtDateOfBirth').value; if (document.getElementById('txtDateOfBirth').value=="") { alert(strMsg); document.getElementById('txtDateOfBirth').value=""; document.getElementById('txtDateOfBirth').focus(); return false; } // 8 ddlSecQuestion var strValue=document.getElementById('ddlSecQuestion').value; if (document.getElementById('ddlSecQuestion').value=="-1") { alert(strMsg); document.getElementById('ddlSecQuestion').focus(); return false; } // 9 txtAnswer var strValue=document.getElementById('txtAnswer').value; if (document.getElementById('txtAnswer').value=="") { alert(strMsg); document.getElementById('txtAnswer').value=""; document.getElementById('txtAnswer').focus(); return false; } // 10 verificationofCode var strValue=document.getElementById('txtForVerficationOfCode').value; if (document.getElementById('txtForVerficationOfCode').value=="") { alert('Enter Verification Code'); document.getElementById('txtForVerficationOfCode').value=""; document.getElementById('txtForVerficationOfCode').focus(); return false; } }

//10
function ZipCode(){
var strZip = document.getElementById('txtZipCode').value; strZip = strZip.toString();
if ((strZip.length > 5 )) { alert('Can not exceed 5') document.getElementById('txtZipCode').value=""; document.getElementById('txtZipCode').focus(); return false;
} // fr digit only var digitonly = /^[-]?\d*\.?\d*$/; if(!strZip.match(digitonly)) { alert('Must Enter Digit') document.getElementById('txtZipCode').value=""; document.getElementById('txtZipCode').focus(); return false; } } // function for phone validations function Phone() { var strLength = document.getElementById('txtPhone1').value; if(strLength.search(/[^0-9]/) != -1) { document.getElementById('txtPhone1').value = ''; alert('Enter digit only');f return false; } strLength = strLength.toString();
if (strLength.length ==3) { // alert(strLength.length) document.getElementById('txtPhone2').focus(); return false; } } function Phone2() { var strLength = document.getElementById('txtPhone2').value; if(strLength.search(/[^0-9]/) != -1) { document.getElementById('txtPhone2').value = ''; alert('Enter digit only'); return false; } var strLength2 = document.getElementById('txtPhone2').value; strLength2 = strLength2.toString();
if (strLength2.length ==3) { // alert(strLength.length) document.getElementById('txtPhone3').focus(); return false; } } function Phone3() { var strLength = document.getElementById('txtPhone3').value; if(strLength.search(/[^0-9]/) != -1) { document.getElementById('txtPhone3').value = ''; alert('Enter digit only'); return false; } } // zip code
function ZipCode() { var strLength = document.getElementById('txtZipCode').value; if(strLength.search(/[^0-9]/) != -1) { document.getElementById('txtZipCode').value = ''; alert('Enter digit only'); return false; } } // /^[a-zA-Z]+$/ function Alphabatic() { var name=document.getElementById('txtFirstName').value; for(i=0;i=65 && name.charCodeAt(i)<=90)(name.charCodeAt(i)>=97 && name.charCodeAt(i)<=122)(name.charCodeAt(i)==32))) { alert('Alphabets only'); document.getElementById('txtFirstName').value=""; document.getElementById('txtFirstName').focus(); return false } } } function AlphabaticLasName() { var name=document.getElementById('txtLastName').value; for(i=0;i=65 && name.charCodeAt(i)<=90)(name.charCodeAt(i)>=97 && name.charCodeAt(i)<=122)(name.charCodeAt(i)==32))) { alert('Alphabates only'); document.getElementById('txtLastName').value=""; document.getElementById('txtLastName').focus(); return false } } }

1 comment:

helpondesk said...

it has no feel n look