How can I write a Regex to do this?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I want to write a regular expression, I hear that using this can find
inconsistancies in input.

Here is what I need the expression to do.

Verify part numbers hat are in the following format would return true.

will begin with a C, V, K, or J.
followed by a dash than a five digit number begining with an 8 or 9
followed by a dash and then a three digit number ending in 1

so a valid number would be:

K-82205-001

can anyone show me how I would write a regular expression to verify
this?
 
I want to write a regular expression, I hear that using this can find
inconsistancies in input.

Here is what I need the expression to do.

Verify part numbers hat are in the following format would return true.

will begin with a C, V, K, or J.
followed by a dash than a five digit number begining with an 8 or 9
followed by a dash and then a three digit number ending in 1

so a valid number would be:

K-82205-001

can anyone show me how I would write a regular expression to verify
this?

<aircode>
Dim R As New System.Text.RegularExpressions.Regex( _
"[CVKJ]-[89]\d{4}-\d{2}1")

If R.IsMatch(Text) Then
'... Ok
End If
</aircode>

HTH.

Regards,

Branco.
 
Ron said:
I want to write a regular expression, I hear that using this can find
inconsistancies in input.

Here is what I need the expression to do.

Verify part numbers hat are in the following format would return true.

will begin with a C, V, K, or J.
followed by a dash than a five digit number begining with an 8 or 9
followed by a dash and then a three digit number ending in 1

so a valid number would be:

K-82205-001

can anyone show me how I would write a regular expression to verify
this?

Use this pattern:

^[CVKJ]-[89]\d{4}-\d{2}1$

Example:

If Regex.IsMatch(input, "^[CVKJ]-[89]\d{4}-\d{2}1$") Then
' correct
Else
' incorrect
End If
 
Back
Top