Search This Blog

09 March 2011

Client side Validations

Client side validation runs in client's browser. For every request code is executed at server side and result is sent to the client in simple HTML format. Its performance is faster than server side validations.

// Create a class file and paste in App_code folder

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public class validation
{
public validation()
{

}
public bool Validate(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf(' {
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf(' {
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf('$') == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}) == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate1(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
if (str == "username")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 21)
{
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z'.\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
ctls.BackColor = System.Drawing.Color.White;
return true;
}
public bool Validate2(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "password")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if ((ctls.Text.Trim().Replace("'", "").Length <> 8))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^[a-zA-Z0-9\s]{1,50}$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
}
return true;
}
public bool Validate3(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "desc")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 500)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
private bool ValidateDate(string date)
{
try
{
// for US, alter to suit if splitting on hyphen, comma, etc.
string[] dateParts = date.Split('/');

// create new date from the parts; if this does not fail
// the method will return true and the date is valid
DateTime testDate = new
DateTime(Convert.ToInt32(dateParts[2]),
Convert.ToInt32(dateParts[0]),
Convert.ToInt32(dateParts[1]));

return true;
}
catch
{
// if a test date cannot be created, the
// method will return false
return false;
}
}

public bool Validate4(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "address")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
if (ctls.Text.Trim().Replace("'", "").Length > 250)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;

}
else
{

return true;
}
}
return true;
}
public bool validateDate(TextBox t1, TextBox t2)
{
bool temp=false;
if (Convert.ToDateTime(t1.Text).CompareTo(Convert.ToDateTime(t2.Text)) > 0)
{
temp=false;
}
else
{
temp = true;
}
return temp;
}

public bool Validate5(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "fname1")
{
if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 30)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.IndexOf('*') == 0 || ctls.Text.IndexOf('?') == 0 || ctls.Text.IndexOf('!') == 0 || ctls.Text.IndexOf('@') == 0 || ctls.Text.IndexOf('#') == 0 || ctls.Text.IndexOf('$') == 0 || ctls.Text.IndexOf('%') == 0 || ctls.Text.IndexOf('^') == 0 || ctls.Text.IndexOf('<') == 0 || ctls.Text.IndexOf('>') == 0)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
public bool Validate6(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "pincode")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length > 6)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool Validate7(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "phoneno")
{
if (string.IsNullOrEmpty(ctls.Text.Trim().Replace("'", "")))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (ctls.Text.Trim().Replace("'", "").Length >10)
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{
return true;
}
}
return true;
}
public bool dcheck(Control ctl)
{
DropDownList dl = new DropDownList();
dl = (DropDownList)ctl;
if (dl.SelectedIndex == 0)
{
return false;
}
else
{
return true;
}
}

public bool chkNumeric(Control ctl)
{
TextBox tx = new TextBox();
tx = (TextBox)ctl;
try
{
string i;
i = Convert.ToString(Convert.ToInt64(tx.Text));
}
catch (Exception e)
{
tx.BackColor = System.Drawing.Color.LightYellow;
return false;
}
return true;
}
public bool email(Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;

if (string.IsNullOrEmpty(ctls.Text.Trim()))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
if (!Regex.IsMatch(ctls.Text.Trim().Replace("'", ""), @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}

return true;
}

public bool ValidateConfirmPassword( Control Ctl, Control Ctlc)
{
TextBox ctls = new TextBox();
ctls = (TextBox)Ctl;
ctls.BackColor = System.Drawing.Color.White;
TextBox ctlsc = new TextBox();
ctlsc = (TextBox)Ctlc;
ctlsc.BackColor = System.Drawing.Color.White;


if (ctls.Text.Trim() != ctlsc.Text.Trim())
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}
if (ctlsc.Text.Trim().Length < 6)
{
ctlsc.BackColor = System.Drawing.Color.LightYellow;
ctlsc.Focus();
return false;

}

return true;
}
public bool ischeckBoxChecked(CheckBox c1, CheckBox c2, CheckBox c3)
{
if (c1.Checked == false && c2.Checked == false && c3.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermschkBxChecked(CheckBox c1)
{
if (c1.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool istermrdChecked(RadioButton rd)
{
if (rd.Checked == false)
{
return false;
}
else
{
return true;
}
}
public bool ValidateChar(string str, Control ctl)
{
TextBox ctls = new TextBox();
ctls = (TextBox)ctl;
ctls.BackColor = System.Drawing.Color.White;
if (str == "url")
{
if (Regex.IsMatch(ctls.Text.Trim(), @"[0-9]"))
{
ctls.BackColor = System.Drawing.Color.LightYellow;
ctls.Focus();
return false;
}
else
{

return true;
}
}
return true;
}
}

3 comments:

  1. hi ma'am,
    a database is created on access & i want access my database in sql how it will done

    ReplyDelete
  2. what is the meaning of . in .net ??

    ReplyDelete