6Aug/090
Valida TextBox si es Entero o Decimal
Bueno estas funciones ayudan a validar si el texto ingresado en un textbox es un valor numérico ó es un valor decimal, estas son de las validaciones más usadas para desarrollar así que acá se los dejo.
VB.NET:
-
Public Shared Function EsInteger(ByVal theValue As String) As Boolean
-
'funcion para enteros
-
Try
-
Convert.ToInt32(theValue)
-
Return True
-
Catch
-
Return False
-
End Try
-
End Function
-
-
Public Shared Function EsDecimal(ByVal theValue As String) As Boolean
-
'funcion para enteros
-
Try
-
Convert.ToDecimal(theValue)
-
Return True
-
Catch
-
Return False
-
End Try
-
End Function
C#:
-
public static bool EsInteger(string theValue)//funcion para enteros
-
{
-
try
-
{
-
Convert.ToInt32(theValue);
-
return true;
-
}
-
catch
-
{
-
return false;
-
}
-
}
-
-
public static bool EsDecimal(string theValue)//funcion para enteros
-
{
-
try
-
{
-
Convert.ToDecimal(theValue);
-
return true;
-
}
-
catch
-
{
-
return false;
-
}
-
}
otra manera de validar de parte de @cmsalvado gracias por el dato:
VB.NET:
-
Public Shared Function EsInteger(ByVal theValue As String) As Boolean
-
Dim value As Integer
-
Return Integer.TryParse(theValue, value)
-
End Function
C#:
-
public static bool EsInteger(string theValue)
-
{
-
int value;
-
return int.TryParse(theValue, out value);
-
}
bueno espero les sea de gran ayuda.
nos vemos
No TweetBacks yet. (Be the first to Tweet this post)




























