- For Email- Validation.
function email()
{
src = document.form1.Email.value;
var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
var regex = new RegExp(emailReg);
var c = regex.test(src);
if(c == false && src !="" )
{
alert("Please Enter valid email address");
document.form1.Email.select();
}
} - For Postalcode validation.
function PostalCodes()
{
var poscod =document.form1.PostalCode.value;
var lenpcod = poscod.length;
if(isNaN(poscod) lenpcod!=6 && poscod!="")
{
alert("Enter valid Postal Code");
document.form1.PostalCode.select();
}
} - For All Field should not be Blank.
function chkerr(f,chkval){
var chkvalarr = chkval.split(",");
var totform = document.forms.length;
for(var fm=0;fmfor(var i=0;i for(var j=0;j<=chkvalarr.length;j++){
if(document.forms[fm].elements[i].value == "" && document.forms[fm].elements[i].name == chkvalarr[j]){
alert(document.forms[fm].elements[i].name +" Should not blank");
document.forms[fm].elements[i].focus();
document.forms[fm].elements[i].style.background="lightyellow";
return false;
}
}
}
}
} - For Year Validation .
function yr()
{
var flag = 0;
var yea = document.form1.Year.value;
var mnth = document.form1.Month.value;
var dt = document.form1.Day.value;
var len = yea.length;
if(yea!="")
{
if(yea%400==0 yea%100==0 yea%4==0)
{
flag=1;
}
if((!isNaN(yea) && len ==4))
{
if(mnth==2)
{
if(flag==1)
{
if(dt>29)
{
alert("Invalid Day");
document.form1.Day.select();
return false;
}
}
else
{
if(dt>28)
{
alert("Invalid Day");
document.form1.Day.select();
}
}
}
}
else
{
alert("Invalid Year");
document.form1.Year.select();
}
}
} - For Date Validation.
function dt()
{
var day = document.form1.Day.value;
var mnth = document.form1.Month.value;
var len = day.length;
var flag=0;
if(mnth == 1 mnth == 3 mnth == 5 mnth == 7 mnth == 8 mnth == 10 mnth == 12)
{
flag = 1;
}
else
{
flag = 0;
}
if(flag==1)
{
if((isNaN(day) && day!="") ( len>2 && day!="") ( day >31 && day!="") (mnth==2 && day >29 && day!="" ) )
{
alert("Enter Valid Day");
document.form1.Day.select();
return false;
}
}
else if(flag==0)
{
if((isNaN(day) && day!="") ( len>2 && day!="") ( day >30 && day!="") (mnth==2 && day >29 && day!="" ) )
{
alert("Enter Valid Day");
document.form1.Day.select();
return false;
}
}
}
function PostalCodes()
{
var poscod =document.form1.PostalCode.value;
var lenpcod = poscod.length;
if(isNaN(poscod) lenpcod!=6 && poscod!="")
{
alert("Enter valid Postal Code");
document.form1.PostalCode.select();
}
} - For Chaking From DB Whether Email is aveleble or not.
function emailavil()
{
var ema = document.form1.Email.value;
sndUserCheck(ema);
}
// Include Followin js file for checking from db;
// JScript File
var ajax;
function MyObject(){
if(window.XMLHttpRequest)
{
ajax = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}else {
ajax = new ActiveXObject("MSXML2.XMLHTTP");
}
return ajax;
}
function handelResponse(){
var serverres;
if (ajax.readyState== 4) {
if (ajax.status== 200) {
serverres = ajax.responseText;
alert(serverres.substr(0,15));
}
}
}
function sndUserCheck(action)
{
MyObject();
ajax.open("GET","Default.aspx?t1="+action,true);
ajax.onreadystatechange = handelResponse;
ajax.send(null);
}
// c# part.
SqlConnection conn;
SqlCommand cmd;
string email = Request.QueryString.Get("t1");
if (email != null)
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ExamConnectionString"].ConnectionString);
cmd = new SqlCommand("select count(*) from UserMaster where EmailID='" + email + "'",conn);
conn.Open();
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
Response.Write("Not Availeble");
}
else
{
Response.Write("Availeble");
}
conn.Close();
}
}
No comments:
Post a Comment