Datagridview Excepcion al Intentar Ordenar elementos
Editar en Columns, Collection, SortMode = NotSortable
jueves, 16 de octubre de 2014
miércoles, 15 de octubre de 2014
Validaciones usando Regex
Entrada alphanumérica (sin caracteres especiales): Aceptando letras de A-Z (mayúsculas y minúsculas), números 0-9, y la tecla backspace.
private void alphaNumericTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var regex = new Regex(@"[^a-zA-Z0-9\b]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}
Entrada alphanumérica (separada por espacios, sin caracteres especiales): Aceptando letras de A-Z (mayúsculas y minúsculas), números 0-9, espacio y la tecla backspace.
private void alphaNumericPlusSpaceTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var regex = new Regex(@"[^a-zA-Z0-9\x20\b]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}
Dirección Ip:
if (!(string.IsNullOrEmpty(txbIpAddress.Text)) && (Regex.IsMatch(txbIpAddress.Text, @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")))
{
RegECRUdp(1, txbIpAddress.Text, "", 5002, false);
testResult = TransTestComm(1, 0);
}
else
{
MessageBox.Show("Dirección Ip inválida.");
return;
}
Email:
private void txbEmail_Validating(object sender, CancelEventArgs e)
{
string email = txbEmail.Text;
Regex regex1 = new Regex(@"\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z");
Regex regex2 = new Regex(@"^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*");
Match match1 = regex1.Match(email);
Match match2 = regex2.Match(email);
if (match1.Success && match2.Success)
{
lblEmail.ForeColor = Color.Black;
lblRequiredFieldForInfoStore3.ForeColor = Color.Goldenrod;
}
else
{
lblEmail.ForeColor = Color.Red;
lblRequiredFieldForInfoStore3.ForeColor = Color.Red;
return;
}
}
Regular Expression Library: Buscador de expresiones regulares
http://regexlib.com/
private void alphaNumericTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var regex = new Regex(@"[^a-zA-Z0-9\b]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}
Entrada alphanumérica (separada por espacios, sin caracteres especiales): Aceptando letras de A-Z (mayúsculas y minúsculas), números 0-9, espacio y la tecla backspace.
private void alphaNumericPlusSpaceTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var regex = new Regex(@"[^a-zA-Z0-9\x20\b]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}
Dirección Ip:
if (!(string.IsNullOrEmpty(txbIpAddress.Text)) && (Regex.IsMatch(txbIpAddress.Text, @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")))
{
RegECRUdp(1, txbIpAddress.Text, "", 5002, false);
testResult = TransTestComm(1, 0);
}
else
{
MessageBox.Show("Dirección Ip inválida.");
return;
}
Email:
private void txbEmail_Validating(object sender, CancelEventArgs e)
{
string email = txbEmail.Text;
Regex regex1 = new Regex(@"\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z");
Regex regex2 = new Regex(@"^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*");
Match match1 = regex1.Match(email);
Match match2 = regex2.Match(email);
if (match1.Success && match2.Success)
{
lblEmail.ForeColor = Color.Black;
lblRequiredFieldForInfoStore3.ForeColor = Color.Goldenrod;
}
else
{
lblEmail.ForeColor = Color.Red;
lblRequiredFieldForInfoStore3.ForeColor = Color.Red;
return;
}
}
Regular Expression Library: Buscador de expresiones regulares
http://regexlib.com/
Etiquetas:
.Net,
C#,
Expresiones regulares,
KeyPress,
Regex,
Regular expressions,
Textbox,
Validating
Suscribirse a:
Comentarios (Atom)