none
validation problem

    Question

  • Hi All.

    I validate couple TextBox field for numeric. That works fine. But when I type in only double zero in one of the field I have validation issue. My validation code:

    Public Class RequiredString
        Inherits ValidationRule
    
        Private _ObjectType As String
    
        Public Property ObjectType() As String
            Get
                Return _ObjectType
            End Get
            Set(ByVal value As String)
                _ObjectType = value
            End Set
        End Property
    
        Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As System.Windows.Controls.ValidationResult
            If _ObjectType = "Integer" Then
                If Not IsNumeric(value) Then
                    Return New ValidationResult(False, "A value must be numeric")
                End If
            End If
    
            Return New ValidationResult(True, Nothing)
        End Function
    End Class

    How fix that problem?

    Thanks.

    Monday, November 05, 2012 5:34 PM

Answers

  • Hi eugzl,

    If you want to check the value is numberic or not, you could use

    if (_ObjectType == "Integer")
    {
    
            int number;
            if(! Int32.TryParse((String)value,out number))
                return new ValidationResult(false, "Illegal characters");
                   
    }

    and then when you type "00", you will not get the validation issue.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 06, 2012 7:16 AM
    Moderator

All replies

  • Hi eugzl,

    If you want to check the value is numberic or not, you could use

    if (_ObjectType == "Integer")
    {
    
            int number;
            if(! Int32.TryParse((String)value,out number))
                return new ValidationResult(false, "Illegal characters");
                   
    }

    and then when you type "00", you will not get the validation issue.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 06, 2012 7:16 AM
    Moderator
  • Hi eugzl,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 22, 2012 6:56 AM
    Moderator