AlHal2
asked on
validate textbox that can contain set of 3 digits separated by a space.
I have a textbox that can contain any number of space delimited strings.
Each string must be 3 digits.
The first 2 digits must be letters. The third must be a number.
AA4 BE9 II4 Valid
AA4BE9 Invalid as there is no space
AA4 BEK Invalid as the last digit is a K not a number
AA9 PO5 WW3 QQ4 invalid as there are 2 spaces between WW3 and QQ4
ZZ3 Valid
I'm using vb 2008 with asp.net 3.5.
Each string must be 3 digits.
The first 2 digits must be letters. The third must be a number.
AA4 BE9 II4 Valid
AA4BE9 Invalid as there is no space
AA4 BEK Invalid as the last digit is a K not a number
AA9 PO5 WW3 QQ4 invalid as there are 2 spaces between WW3 and QQ4
ZZ3 Valid
I'm using vb 2008 with asp.net 3.5.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why don't you use regex to check if the string consists of two characters and a digiti, followed byzero or more sets of 'a space followed by two characters and a digit'?
From the top of my head something like:
[A-Za-z][A-Za-z][0-9](\ [A-Za-z][A-Za-z][0-9])*
From the top of my head something like:
[A-Za-z][A-Za-z][0-9](\ [A-Za-z][A-Za-z][0-9])*
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
ASKER
If txtDatatypes.Text.Length Mod 4 = 3 Then
For RegexCount = 0 To txtDatatypes.Text.Length - 1
If RegexCount Mod 4 = 0 Or RegexCount Mod 4 = 1 Then
If Not Regex.Match(txtDatatypes.T
lblErrs.Text = "The " + (RegexCount + 1).ToString + "th character must be a letter"
Exit Sub
End If
End If
If RegexCount Mod 4 = 2 Then
If Not Regex.Match(txtDatatypes.T
lblErrs.Text = "The " + (RegexCount + 1).ToString + "th character must be a number"
Exit Sub
End If
End If
If RegexCount Mod 4 = 3 Then
If txtDatatypes.Text.Substrin
lblErrs.Text = "The " + (RegexCount + 1).ToString + "th character must be a space"
Exit Sub
End If
End If
Next
Else
lblErrs.Text = "Datatypes box must be a set 3 letter datatypes followed by a space"
Exit Sub
End If