Generating a genuine looking National Insurance Number(NINO)
conrad towner
Posts: 3
Not sure if anyone can help me I am new to using Data Generator.
I need to generate genuine looking NINO's which can be validated using the following REGEX
^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$
He tells me
Essentially this breaks down as follows:
• First two characters cannot be any of the following combinations: BG|GB|NK|KN|TN|NT|ZZ
• First character must be one of the following: A, B, C, E, G, H, J - P, R, S, T, W - Z
• Second character must be one of the following: A, B, C, E, G, H, J - N, P, R, S, T, W - Z
• Followed by exactly 6 digits
• Last character must be one of the following: A - D
I can create the string but don't know how to exclude certain combinations of letters for the first 2 characters of the NINO
I am using
[ABEGHJKLMNOPRSTWXYZ]{1}[ABCEGHJKLMNPRSTWXYZ]{1}\d{6}[A-D]{1}
I need to generate genuine looking NINO's which can be validated using the following REGEX
^(?!BG|GB|NK|KN|TN|NT|ZZ)[ABCEGHJ-PRSTW-Z][ABCEGHJ-NPRSTW-Z]\d{6}[A-D]$
He tells me
Essentially this breaks down as follows:
• First two characters cannot be any of the following combinations: BG|GB|NK|KN|TN|NT|ZZ
• First character must be one of the following: A, B, C, E, G, H, J - P, R, S, T, W - Z
• Second character must be one of the following: A, B, C, E, G, H, J - N, P, R, S, T, W - Z
• Followed by exactly 6 digits
• Last character must be one of the following: A - D
I can create the string but don't know how to exclude certain combinations of letters for the first 2 characters of the NINO
I am using
[ABEGHJKLMNOPRSTWXYZ]{1}[ABCEGHJKLMNPRSTWXYZ]{1}\d{6}[A-D]{1}
Comments
Data Generator does some custom parsing of regular expressions, so it expects a non-special character to follow "?". That means it can't process negative lookahead ("?!"). I'm looking into workarounds but I suspect the workaround would be to implement the regex in the Python generator or by writing a custom generator for your use case.
First, install Python 2.7 x86 from http://www.python.org/download/
Then get setuptools for Python 2.7 https://pypi.python.org/pypi/setuptools
Then download setup.py from https://github.com/asciimoo/exrex
Install exrex from the command-line using python setup.py install
In your Python root folder (c:\python27) locate the lib subfolder
Edit exrex.py and locate the line
from re import sre_parse, U
Before this add the line import sre_parse and change the line to read from re import U
Reason this did not work for me, I suppose exrex was written for a different version of python before they moved sre_parse to its' own module.
Now you can use this code
You are an absolute star
Please note that this fails when using certain versions of Python.
It works correctly when using 2.7.6 x86.
Thank you,
Product Support Engineer
Redgate Software Ltd
Please see our Help Center for detailed guides on how to use our tools