Question need a REGEX pattern to match

cocacola

New member
Joined
Mar 17, 2011
Messages
1
Programming Experience
5-10
need help with validating a 9-digit number.
CANNOT BE -----------
000000000
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
4-5 position(s) CANNOT BE 00 --
123001234
6-9 position(s) CANNOT BE 00 --
234550000
The nine numbers CANNOT BE sequential -- but only the following 4 four below, for the time being --
012345678
123456789
987654321
098765432

I had just managed to get the first piece done --
"^(?:(?!0+|1+|2+|3+|4+))\d{9}$"
Thanks a TON for the help friends.
 
not sure I'd do this with regex. Custom code would likely be faster

VB.NET:
Function IsOK(str as String) as Boolean
If str.Replace(str(0).ToString(), "") = "" Then
  Return False
End If
If (str(3) = "0"c AndAlso str(4) = "0"c) OrElse (str(5) = "0"c AndAlso str(6) = "0"c AndAlso str(7) = "0"c AndAlso str(8) = "0"c) Then
  Return False
End If
Dim i as Integer = 0
c as Char = "a"
Do
  c = str(i)
  i += 1
While i < 9 AndAlso Math.Abs(DirectCast(str(i), Integer) - DirectCast(c, integer)) = 1
If i = 9 Then
  Return False
End If

Not sure on the last one, might need a bit of debugging, but the basic idea is to sub the numeric value of one char from the next one to it, and absolute the reuslt.. if it's 1 theyre sequntial and the loop continues. if the loop got to the end, its a sequential numbered sequence
For i as Integer = 0 to 9
 
Back
Top