|
-
April 2nd, 2009, 08:42 AM
#1
Regex code not working
Hi,
I have written a short piece of code to validate a UK NI number.
The format is 2 upper case letters, followed by 6 digits followed by A,B, C or D
eg AB123456A is OK
This code does not work, it never matches even when the string NI_Num is OK:
Dim NIr As Regex
Dim match As Boolean
NIr = New Regex("^[A-Z]^2[0-9]^6[A,B,C,D]")
match = NIr.IsMatch(NI_Num(count))
match is always false. Any suggestions where I'm going wrong?
Tia
H
Last edited by happyme; April 2nd, 2009 at 08:52 AM.
I'm using .NET Framework 3.5
I'm planning to be spontaneous tomorrow
-
April 2nd, 2009, 09:22 AM
#2
Re: Regex code not working
I just did a search on RegEx Lib and they have posted a Regular Expression for validating UK National Identification numbers here:
http://regexlib.com/REDetails.aspx?regexp_id=527
-
April 6th, 2009, 11:16 AM
#3
Re: Regex code not working
 Originally Posted by happyme
Hi,
I have written a short piece of code to validate a UK NI number.
The format is 2 upper case letters, followed by 6 digits followed by A,B, C or D
eg AB123456A is OK
...
Code:
Dim NIr As Regex
Dim match As Boolean
NIr = New Regex("^[A-Z]^2[0-9]^6[A,B,C,D]")
match = NIr.IsMatch(NI_Num(count))
match is always false. Any suggestions where I'm going wrong?
Tia
H
"^" means "begining of line or string".
Try Expresso software to understand and debug regular expressions.
By the way, you probably want this:
Code:
"^[A-Z]{2}[0-9]{6}[A,B,C,D]"
[Vb.NET 2008 (ex Express)]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|