/(^[XYZ]\d{7}\d?|^\d{8})[A-HJ-NP-TV-Z]$/
Simple regex to see if a string is a valid DNI/NIE number.
DNI/NIE numbers are spanish identification numbers. DNI are for spanish nationals and NIE are for foreigners living in Spain.
This will only take you so far. To fully verify the DNI/NIE you will have to:
DNI: Take the part in front of the letter. Convert it to a number. User modulus 23 on it. Use the result to index into TRWAGMYFPDXBNJZSQVHLCKE and see if the last letter matches (so for 01234567H you would run 1234567%23 = 19 and the 19:th char in the array is C, the number is not a valid DNI)
NIE: If the number is 8 digits long cut the leading letter and run the rest as if it was a DNI. If the number is 7 digits long change the leading letter to a number (X->0, Y->1, Z->2) and run it as if it was a DNI.
#+ Some simple tests
# Valid NIE
X1234567G
# Valid, old NIE
X01234567H
X09375379G
# Valid DNI
01234567H
39027217N
77122981W
37354021F
46724451C
#- Random variations and common mistakes
G1234567G
X1234567U
1234567U
234567H
X-1234567G