views:

136

answers:

1

Hi

I want to use a validator to compare 2 text box in such a way that ,

If V is in Text box 1, means User must type any of the numbers prefix V in Textbox 2 (V00001 to V00050).Other than V ,if they type any other Letters means error message must be shown.

Just like that if C is in TextBox 1 means user must type C00001 in TextBox2.(or any number from C00001 TO C00050) iF S is in textbox 1 means,User must Type S00001(S00001 TO S00050)

Thanks

+1  A: 

Use this method:

// C#
public static bool IsValid(string textBox1Text, string textBox2Text)
{
    return new System.Text.RegularExpressions.Regex(@"^" + textBox1Text + "000[0-4][0-9]$").IsMatch(textBox2Text) || string.Equals(textBox2Text, textBox1Text + "00050");
}

' VB
Public Shared Function IsValid(ByVal textBox1Text As String, ByVal textBox2Text As String) As Boolean
    Return New System.Text.RegularExpressions.Regex("^" + textBox1Text + "000[0-4][0-9]$").IsMatch(textBox2Text) OrElse String.Equals(textBox2Text, textBox1Text + "00050")
End Function
M. Jahedbozorgan