I want to validate NIC number text field in my vb form. It should contain 9 numbers [0-9]
and one letter (letter should be "v"
) (first 9 characters are numbers,last one is a letter)
How do I validate such a thing using regular expression?
Can you help me with the code?
I'm new to this section.
Asked
Active
Viewed 482 times
0

Ahmed ilyas
- 5,722
- 8
- 44
- 72

thilim9
- 227
- 2
- 8
- 17
-
1What regex have you tried? – doctorlove Jun 19 '14 at 08:44
-
I didn't, I'm new to this area. – thilim9 Jun 19 '14 at 08:46
2 Answers
2
The examples section in the docs shows you.
To match a digit use \d
To match 9 numbers you state you want 9: \d{9}
To match a letter you want [a-zA-Z]
(or something more complicated depending on what a letter is). If you specifically want v
then just allow v
using [v]
i.e. \d{9}[v]
Test this with Regex.IsMatch

Community
- 1
- 1

doctorlove
- 18,872
- 2
- 46
- 62
1
Try this:
If Not System.Text.RegularExpressions.Regex.IsMatch(TextBox1.Text, "[0-9]{9}v") Then
MessageBox.Show("Not valid NIC")
End If

ZeroWorks
- 1,618
- 1
- 18
- 22