Today , we discussed about Percentage Validation in VB.Net
Dim RegExpression As Regex
Dim RegExpression1 As Regex
RegExpression = New Regex("^((100.00)|([1-9][0-9]|[1-9]|)(\.\d\d))$")
RegExpression1 = New Regex("^((100)|([1-9][0-9]|[1-9]|))$")
If RegExpression.IsMatch(TextBox3.Text) Or RegExpression1.IsMatch(TextBox3.Text) Then
If TextBox3.Text <> "" Then
Dim Dec As Double = CDbl(TextBox1.Text) * CDbl(TextBox3.Text) / 100
Dec = Math.Round(CDbl(Dec), 2, MidpointRounding.ToEven)
TextBox2.Text = Dec.ToString()
Dim result As Double = Math.Round(Dec, 0, MidpointRounding.AwayFromZero)
TextBox4.Text = result.ToString()
End If
Else
MsgBox("Not a match!")
TextBox3.Text = ""
TextBox3.Focus()
End If
Dim RegExpression1 As Regex
RegExpression = New Regex("^((100.00)|([1-9][0-9]|[1-9]|)(\.\d\d))$")
RegExpression1 = New Regex("^((100)|([1-9][0-9]|[1-9]|))$")
If RegExpression.IsMatch(TextBox3.Text) Or RegExpression1.IsMatch(TextBox3.Text) Then
If TextBox3.Text <> "" Then
Dim Dec As Double = CDbl(TextBox1.Text) * CDbl(TextBox3.Text) / 100
Dec = Math.Round(CDbl(Dec), 2, MidpointRounding.ToEven)
TextBox2.Text = Dec.ToString()
Dim result As Double = Math.Round(Dec, 0, MidpointRounding.AwayFromZero)
TextBox4.Text = result.ToString()
End If
Else
MsgBox("Not a match!")
TextBox3.Text = ""
TextBox3.Focus()
End If